Search in sources :

Example 1 with SpimDataException

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);
    }
}
Also used : XmlIoSpimDataMinimal(bdv.spimdata.XmlIoSpimDataMinimal) SpimDataException(mpicbg.spim.data.SpimDataException) Hdf5ImageLoader(bdv.img.hdf5.Hdf5ImageLoader) XmlIoSpimDataMinimal(bdv.spimdata.XmlIoSpimDataMinimal) SpimDataMinimal(bdv.spimdata.SpimDataMinimal) BasicImgLoader(mpicbg.spim.data.generic.sequence.BasicImgLoader)

Example 2 with SpimDataException

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;
    }
}
Also used : SpimDataException(mpicbg.spim.data.SpimDataException) XmlIoSpimData(mpicbg.spim.data.XmlIoSpimData) SpimData(mpicbg.spim.data.SpimData) RepeatingReleasedEventsFixer(org.janelia.utility.ui.RepeatingReleasedEventsFixer) BigWarp(bigwarp.BigWarp) XmlIoSpimData(mpicbg.spim.data.XmlIoSpimData) ProgressWriterIJ(bdv.ij.util.ProgressWriterIJ)

Example 3 with SpimDataException

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;
    }
}
Also used : SpimDataException(mpicbg.spim.data.SpimDataException) GenericDialogPlus(fiji.util.gui.GenericDialogPlus) SpimData(mpicbg.spim.data.SpimData) RepeatingReleasedEventsFixer(org.janelia.utility.ui.RepeatingReleasedEventsFixer) ProgressWriterIJ(bdv.ij.util.ProgressWriterIJ) ImagePlus(ij.ImagePlus) BigWarp(bigwarp.BigWarp) File(java.io.File)

Example 4 with SpimDataException

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;
}
Also used : SpimDataException(mpicbg.spim.data.SpimDataException) JFileChooser(javax.swing.JFileChooser) ViewTransformAffine(mpicbg.spim.data.registration.ViewTransformAffine) XmlIoSpimData(mpicbg.spim.data.XmlIoSpimData) File(java.io.File) Point(java.awt.Point) RealPoint(net.imglib2.RealPoint) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Example 5 with SpimDataException

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;
}
Also used : XmlIoSpimDataMinimal(bdv.spimdata.XmlIoSpimDataMinimal) SpimDataException(mpicbg.spim.data.SpimDataException) SpimSource(bdv.SpimSource) XmlIoSpimDataMinimal(bdv.spimdata.XmlIoSpimDataMinimal) SpimDataMinimal(bdv.spimdata.SpimDataMinimal) ViewId(mpicbg.spim.data.sequence.ViewId) ViewRegistration(mpicbg.spim.data.registration.ViewRegistration)

Aggregations

SpimDataException (mpicbg.spim.data.SpimDataException)12 SpimData (mpicbg.spim.data.SpimData)5 SpimDataMinimal (bdv.spimdata.SpimDataMinimal)4 XmlIoSpimDataMinimal (bdv.spimdata.XmlIoSpimDataMinimal)4 File (java.io.File)4 XmlIoSpimData (mpicbg.spim.data.XmlIoSpimData)4 ProgressWriterIJ (bdv.ij.util.ProgressWriterIJ)2 BigWarp (bigwarp.BigWarp)2 RepeatingReleasedEventsFixer (org.janelia.utility.ui.RepeatingReleasedEventsFixer)2 Document (org.jdom2.Document)2 Element (org.jdom2.Element)2 SAXBuilder (org.jdom2.input.SAXBuilder)2 SpimSource (bdv.SpimSource)1 ProgressWriterConsole (bdv.export.ProgressWriterConsole)1 Hdf5ImageLoader (bdv.img.hdf5.Hdf5ImageLoader)1 ConverterSetup (bdv.tools.brightness.ConverterSetup)1 ManualTransformation (bdv.tools.transformation.ManualTransformation)1 BdvFunctions (bdv.util.BdvFunctions)1 BdvHandle (bdv.util.BdvHandle)1 BdvStackSource (bdv.util.BdvStackSource)1