use of mpicbg.spim.data.SpimDataException in project labkit-ui by juglab.
the class HDF5Saver method writeXml.
private void writeXml() {
try {
BasicImgLoader imgLoader = new Hdf5ImageLoader(hdf5, partitions, data.getSequenceDescription());
SpimDataMinimal spimData = new SpimDataMinimal(data, imgLoader);
new XmlIoSpimDataMinimal().save(spimData, xml.getAbsolutePath());
} catch (SpimDataException e) {
throw new RuntimeException(e);
}
}
use of mpicbg.spim.data.SpimDataException in project bigwarp by saalfeldlab.
the class BigWarpBdvCommand method run.
@Override
public void run() {
try {
final SpimData fixedSpimData = new XmlIoSpimData().load(fixedImageXml.getAbsolutePath());
final SpimData movingSpimData = new XmlIoSpimData().load(movingImageXml.getAbsolutePath());
new RepeatingReleasedEventsFixer().install();
final BigWarp.BigWarpData<?> bigWarpData = BigWarpInit.createBigWarpData(movingSpimData, fixedSpimData);
bw = new BigWarp(bigWarpData, "Big Warp", new ProgressWriterIJ());
bw.getViewerFrameP().getViewerPanel().requestRepaint();
bw.getViewerFrameQ().getViewerPanel().requestRepaint();
bw.getLandmarkFrame().repaint();
bw.setMovingSpimData(movingSpimData, movingImageXml);
} catch (final SpimDataException e) {
e.printStackTrace();
return;
}
}
use of mpicbg.spim.data.SpimDataException in project bigwarp by saalfeldlab.
the class BigWarpImagePlusPlugIn method run.
@Override
public void run(final String arg) {
if (IJ.versionLessThan("1.40"))
return;
// don't need any open windows if we're using N5
final int[] ids = WindowManager.getIDList();
// Find any open images
final int N = ids == null ? 0 : ids.length;
final String[] titles = new String[N + 1];
for (int i = 0; i < N; ++i) {
titles[i] = (WindowManager.getImage(ids[i])).getTitle();
}
titles[N] = "<None>";
// Build a dialog to choose the moving and fixed images
final GenericDialogPlus gd = new GenericDialogPlus("Big Warp Setup");
gd.addMessage("Image Selection:");
ImagePlus currimg = WindowManager.getCurrentImage();
String current = titles[N];
if (currimg != null) {
current = currimg.getTitle();
}
gd.addChoice("moving_image", titles, current);
if (titles.length > 1)
gd.addChoice("target_image", titles, current.equals(titles[0]) ? titles[1] : titles[0]);
else
gd.addChoice("target_image", titles, titles[0]);
gd.addMessage("\nN5/Zarr/HDF5/BDV-XML");
gd.addDirectoryOrFileField("Moving", "");
gd.addStringField("Moving dataset", "");
gd.addDirectoryOrFileField("Target", "");
gd.addStringField("Target dataset", "");
gd.addMessage("");
gd.addFileField("Landmarks file", "");
gd.addCheckbox("Apply transform from landmarks", true);
gd.showDialog();
if (gd.wasCanceled())
return;
final int mvgImgIdx = gd.getNextChoiceIndex();
final int tgtImgIdx = gd.getNextChoiceIndex();
movingIp = mvgImgIdx < N ? WindowManager.getImage(ids[mvgImgIdx]) : null;
targetIp = tgtImgIdx < N ? WindowManager.getImage(ids[tgtImgIdx]) : null;
final String mvgRoot = gd.getNextString();
final String mvgDataset = gd.getNextString();
final String tgtRoot = gd.getNextString();
final String tgtDataset = gd.getNextString();
final String landmarkPath = gd.getNextString();
final boolean applyTransform = gd.getNextBoolean();
// build bigwarp data
BigWarpData<?> bigwarpdata = BigWarpInit.initData();
int id = 0;
if (movingIp != null) {
id += BigWarpInit.add(bigwarpdata, movingIp, id, 0, true);
}
SpimData movingSpimData = null;
if (!mvgRoot.isEmpty()) {
if (openWithImageJ(mvgRoot)) {
final ImagePlus mvgIpFromFile = IJ.openImage(mvgRoot);
mvgIpFromFile.show();
BigWarpInit.add(bigwarpdata, mvgIpFromFile, id, 0, true);
} else {
movingSpimData = BigWarpInit.addToData(bigwarpdata, true, id, mvgRoot, mvgDataset);
}
id++;
}
if (targetIp != null) {
id += BigWarpInit.add(bigwarpdata, targetIp, id, 0, false);
}
if (!tgtRoot.isEmpty()) {
if (openWithImageJ(tgtRoot)) {
final ImagePlus tgtIpFromFile = IJ.openImage(tgtRoot);
tgtIpFromFile.show();
BigWarpInit.add(bigwarpdata, tgtIpFromFile, id, 0, false);
} else {
BigWarpInit.addToData(bigwarpdata, false, id, tgtRoot, tgtDataset);
}
id++;
}
bigwarpdata.wrapUp();
// run BigWarp
try {
new RepeatingReleasedEventsFixer().install();
final BigWarp<?> bw = new BigWarp<>(bigwarpdata, "Big Warp", new ProgressWriterIJ());
if (landmarkPath != null && !landmarkPath.isEmpty()) {
bw.loadLandmarks(landmarkPath);
if (applyTransform)
bw.setIsMovingDisplayTransformed(applyTransform);
}
if (movingSpimData != null)
bw.setMovingSpimData(movingSpimData, new File(mvgRoot));
bw.getViewerFrameP().getViewerPanel().requestRepaint();
bw.getViewerFrameQ().getViewerPanel().requestRepaint();
bw.getLandmarkFrame().repaint();
} catch (final SpimDataException e) {
e.printStackTrace();
return;
}
}
use of mpicbg.spim.data.SpimDataException in project bigwarp by saalfeldlab.
the class BigWarp method saveMovingImageXml.
public File saveMovingImageXml(String proposedFilePath) {
if (movingSpimData == null) {
IJ.log("Cannot save warped moving image XML, because the input image was not a BDV/XML.");
return null;
}
final AffineTransform3D bigWarpTransform = getMovingToFixedTransformAsAffineTransform3D();
System.out.println("bigWarp transform as affine 3d: " + bigWarpTransform.toString());
movingSpimData.getViewRegistrations().getViewRegistration(0, 0).preconcatenateTransform(new ViewTransformAffine("Big Warp: " + bwTransform.getTransformType(), bigWarpTransform));
File proposedFile;
if (proposedFilePath == null) {
final JFileChooser fileChooser = new JFileChooser(movingImageXml.getParent());
proposedFile = new File(movingImageXml.getName().replace(".xml", "-bigWarp.xml"));
fileChooser.setSelectedFile(proposedFile);
final int returnVal = fileChooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION)
proposedFile = fileChooser.getSelectedFile();
else
return null;
} else {
proposedFile = new File(proposedFilePath);
}
try {
new XmlIoSpimData().save(movingSpimData, proposedFile.getAbsolutePath());
} catch (SpimDataException e) {
e.printStackTrace();
}
return proposedFile;
}
use of mpicbg.spim.data.SpimDataException in project mars-fx by duderstadt-lab.
the class MarsBdvFrame method loadAsSpimDataMinimal.
private Source<T> loadAsSpimDataMinimal(MarsBdvSource source, MarsMetadata meta) {
SpimDataMinimal spimData;
try {
spimData = new XmlIoSpimDataMinimal().load(source.getPath());
// Add transforms to spimData...
Map<ViewId, ViewRegistration> registrations = spimData.getViewRegistrations().getViewRegistrations();
for (ViewId id : registrations.keySet()) {
if (source.getCorrectDrift()) {
double dX = meta.getPlane(0, 0, 0, id.getTimePointId()).getXDrift();
double dY = meta.getPlane(0, 0, 0, id.getTimePointId()).getYDrift();
registrations.get(id).getModel().set(source.getAffineTransform3D(dX, dY));
} else
registrations.get(id).getModel().set(source.getAffineTransform3D());
}
if (spimData.getSequenceDescription().getTimePoints().size() > numTimePoints)
numTimePoints = spimData.getSequenceDescription().getTimePoints().size();
return new SpimSource<T>(spimData, 0, source.getName());
} catch (SpimDataException e) {
e.printStackTrace();
}
return null;
}
Aggregations