Search in sources :

Example 1 with SpimDataMinimal

use of bdv.spimdata.SpimDataMinimal 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 SpimDataMinimal

use of bdv.spimdata.SpimDataMinimal in project labkit-ui by juglab.

the class HDF5Saver method oneImageSpimData.

private static <T> SpimDataMinimal oneImageSpimData(List<RandomAccessibleInterval<T>> frames, File basePath) {
    List<TimePoint> timePointList = IntStream.range(0, frames.size()).mapToObj(TimePoint::new).collect(Collectors.toList());
    final TimePoints timePoints = new TimePoints(timePointList);
    final BasicViewSetup setup = new BasicViewSetup(0, "image", (Dimensions) frames.get(0), new FinalVoxelDimensions("pixel", 1, 1, 1));
    final Map<Integer, BasicViewSetup> setups = Collections.singletonMap(0, setup);
    final MissingViews missingViews = null;
    BasicImgLoader imgLoader = new BasicImgLoader() {

        @Override
        public BasicSetupImgLoader<T> getSetupImgLoader(int i) {
            if (i != setup.getId())
                throw new IllegalArgumentException();
            return new BasicSetupImgLoader<T>() {

                @Override
                public RandomAccessibleInterval<T> getImage(int timeId, ImgLoaderHint... imgLoaderHints) {
                    return frames.get(timeId);
                }

                @Override
                public T getImageType() {
                    return Util.getTypeFromInterval(frames.get(0));
                }
            };
        }
    };
    final SequenceDescriptionMinimal sequence = new SequenceDescriptionMinimal(timePoints, setups, imgLoader, missingViews);
    List<ViewRegistration> viewRegistrationList = timePointList.stream().map(x -> new ViewRegistration(x.getId(), setup.getId())).collect(Collectors.toList());
    ViewRegistrations registrations = new ViewRegistrations(viewRegistrationList);
    return new SpimDataMinimal(basePath, sequence, registrations);
}
Also used : IntStream(java.util.stream.IntStream) XmlIoSpimDataMinimal(bdv.spimdata.XmlIoSpimDataMinimal) TimePoints(mpicbg.spim.data.sequence.TimePoints) DummyProgressWriter(sc.fiji.labkit.ui.utils.progress.DummyProgressWriter) IntegerType(net.imglib2.type.numeric.IntegerType) Hdf5ImageLoader(bdv.img.hdf5.Hdf5ImageLoader) ArrayList(java.util.ArrayList) BasicImgLoader(mpicbg.spim.data.generic.sequence.BasicImgLoader) FloatType(net.imglib2.type.numeric.real.FloatType) MissingViews(mpicbg.spim.data.sequence.MissingViews) Converter(net.imglib2.converter.Converter) SpimDataMinimal(bdv.spimdata.SpimDataMinimal) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) SubTaskProgressWriter(bdv.export.SubTaskProgressWriter) BasicSetupImgLoader(mpicbg.spim.data.generic.sequence.BasicSetupImgLoader) ViewRegistrations(mpicbg.spim.data.registration.ViewRegistrations) ImgLoaderHint(mpicbg.spim.data.generic.sequence.ImgLoaderHint) Map(java.util.Map) Partition(bdv.img.hdf5.Partition) ViewRegistration(mpicbg.spim.data.registration.ViewRegistration) SpimDataException(mpicbg.spim.data.SpimDataException) ExportMipmapInfo(bdv.export.ExportMipmapInfo) Views(net.imglib2.view.Views) TimePoint(mpicbg.spim.data.sequence.TimePoint) RevampUtils(sc.fiji.labkit.pixel_classification.RevampUtils) UnsignedShortType(net.imglib2.type.numeric.integer.UnsignedShortType) Dimensions(net.imglib2.Dimensions) FinalVoxelDimensions(mpicbg.spim.data.sequence.FinalVoxelDimensions) Util(net.imglib2.util.Util) Collectors(java.util.stream.Collectors) File(java.io.File) ProgressWriter(bdv.export.ProgressWriter) ProposeMipmaps(bdv.export.ProposeMipmaps) SequenceDescriptionMinimal(bdv.spimdata.SequenceDescriptionMinimal) List(java.util.List) BasicViewSetup(mpicbg.spim.data.generic.sequence.BasicViewSetup) DoubleType(net.imglib2.type.numeric.real.DoubleType) Converters(net.imglib2.converter.Converters) RealType(net.imglib2.type.numeric.RealType) Collections(java.util.Collections) WriteSequenceToHdf5(bdv.export.WriteSequenceToHdf5) TimePoints(mpicbg.spim.data.sequence.TimePoints) FinalVoxelDimensions(mpicbg.spim.data.sequence.FinalVoxelDimensions) SequenceDescriptionMinimal(bdv.spimdata.SequenceDescriptionMinimal) TimePoint(mpicbg.spim.data.sequence.TimePoint) ViewRegistration(mpicbg.spim.data.registration.ViewRegistration) ViewRegistrations(mpicbg.spim.data.registration.ViewRegistrations) XmlIoSpimDataMinimal(bdv.spimdata.XmlIoSpimDataMinimal) SpimDataMinimal(bdv.spimdata.SpimDataMinimal) BasicSetupImgLoader(mpicbg.spim.data.generic.sequence.BasicSetupImgLoader) MissingViews(mpicbg.spim.data.sequence.MissingViews) BasicImgLoader(mpicbg.spim.data.generic.sequence.BasicImgLoader) ImgLoaderHint(mpicbg.spim.data.generic.sequence.ImgLoaderHint) BasicViewSetup(mpicbg.spim.data.generic.sequence.BasicViewSetup)

Example 3 with SpimDataMinimal

use of bdv.spimdata.SpimDataMinimal in project bigwarp by saalfeldlab.

the class BigWarpBatchTransform method createSpimData.

public static final SpimDataMinimal createSpimData(IFormatReader reader) {
    Hashtable<String, Object> gmeta = reader.getGlobalMetadata();
    // header stuff here TODO
    System.out.println(gmeta);
    // get relevant metadata
    double pw = 1.0;
    double ph = 1.0;
    double pd = 1.0;
    if (gmeta.keySet().contains("XResolution"))
        pw = ((Double) gmeta.get("XResolution")).doubleValue();
    if (gmeta.keySet().contains("YResolution"))
        ph = ((Double) gmeta.get("YResolution")).doubleValue();
    if (gmeta.keySet().contains("Spacing"))
        pd = ((Double) gmeta.get("Spacing")).doubleValue();
    int numSetups = 1;
    int numTimepoints = 1;
    int[] ids = new int[] { 349812342 };
    final File basePath = new File(".");
    String punit = "px";
    if (gmeta.keySet().contains("Unit"))
        punit = (String) gmeta.get("Unit");
    final FinalVoxelDimensions voxelSize = new FinalVoxelDimensions(punit, pw, ph, pd);
    final long w = ((Long) gmeta.get("ImageWidth")).longValue();
    final long h = ((Long) gmeta.get("ImageLength")).longValue();
    // Long.parseLong( (String)gmeta.get("images") );
    final long d = reader.getSizeZ();
    long[] dims = new long[] { w, h, d };
    final FinalDimensions size = new FinalDimensions(new long[] { w, h, d });
    // create setups from channels
    final HashMap<Integer, BasicViewSetup> setups = new HashMap<Integer, BasicViewSetup>(numSetups);
    for (int s = 0; s < numSetups; ++s) {
        final BasicViewSetup setup = new BasicViewSetup(ids[s], String.format("channel %d", ids[s] + 1), size, voxelSize);
        setup.setAttribute(new Channel(ids[s] + 1));
        setups.put(ids[s], setup);
    }
    // create timepoints
    final ArrayList<TimePoint> timepoints = new ArrayList<TimePoint>(numTimepoints);
    for (int t = 0; t < numTimepoints; ++t) timepoints.add(new TimePoint(t));
    // create ViewRegistrations from the images calibration
    final AffineTransform3D sourceTransform = new AffineTransform3D();
    sourceTransform.set(1.0 / pw, 0, 0, 0, 0, 1.0 / ph, 0, 0, 0, 0, pd, 0);
    final ArrayList<ViewRegistration> registrations = new ArrayList<ViewRegistration>();
    for (int t = 0; t < numTimepoints; ++t) for (int s = 0; s < numSetups; ++s) registrations.add(new ViewRegistration(t, ids[s], sourceTransform));
    final SequenceDescriptionMinimal seq = new SequenceDescriptionMinimal(new TimePoints(timepoints), setups, new DummyImageLoader<FloatType>(new FloatType(), dims), null);
    SpimDataMinimal spimData = new SpimDataMinimal(basePath, seq, new ViewRegistrations(registrations));
    if (WrapBasicImgLoader.wrapImgLoaderIfNecessary(spimData))
        System.err.println("WARNING:\nOpening <SpimData> dataset that is not suited for interactive browsing.\nConsider resaving as HDF5 for better performance.");
    return spimData;
}
Also used : TimePoints(mpicbg.spim.data.sequence.TimePoints) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FloatType(net.imglib2.type.numeric.real.FloatType) FinalDimensions(net.imglib2.FinalDimensions) SpimDataMinimal(bdv.spimdata.SpimDataMinimal) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D) FinalVoxelDimensions(mpicbg.spim.data.sequence.FinalVoxelDimensions) SequenceDescriptionMinimal(bdv.spimdata.SequenceDescriptionMinimal) Channel(mpicbg.spim.data.sequence.Channel) TimePoint(mpicbg.spim.data.sequence.TimePoint) ViewRegistration(mpicbg.spim.data.registration.ViewRegistration) TimePoint(mpicbg.spim.data.sequence.TimePoint) ViewRegistrations(mpicbg.spim.data.registration.ViewRegistrations) File(java.io.File) BasicViewSetup(mpicbg.spim.data.generic.sequence.BasicViewSetup)

Example 4 with SpimDataMinimal

use of bdv.spimdata.SpimDataMinimal in project bigwarp by saalfeldlab.

the class ImagePlusLoader method loadAll.

public SpimDataMinimal[] loadAll(int startid) {
    SpimDataMinimal[] out = new SpimDataMinimal[impList.length];
    index = startid;
    for (int i = 0; i < impList.length; i++) {
        out[i] = load(index, impList[i]);
        index += impList[i].getNChannels();
    }
    return out;
}
Also used : SpimDataMinimal(bdv.spimdata.SpimDataMinimal) TimePoint(mpicbg.spim.data.sequence.TimePoint)

Example 5 with SpimDataMinimal

use of bdv.spimdata.SpimDataMinimal in project bigwarp by saalfeldlab.

the class ImagePlusLoader method load.

public SpimDataMinimal load(final int setupIdOffset, ImagePlus imp) {
    // get calibration and image size
    final double pw;
    final double ph;
    final double pd;
    pw = sanitizeCalibration(imp.getCalibration().pixelWidth, "x");
    ph = sanitizeCalibration(imp.getCalibration().pixelHeight, "y");
    pd = sanitizeCalibration(imp.getCalibration().pixelDepth, "z");
    String punit = imp.getCalibration().getUnit();
    if (punit == null || punit.isEmpty())
        punit = "px";
    final FinalVoxelDimensions voxelSize = new FinalVoxelDimensions(punit, pw, ph, pd);
    final int w = imp.getWidth();
    final int h = imp.getHeight();
    final int d = imp.getNSlices();
    final int numTimepoints = imp.getNFrames();
    final int numSetups = imp.getNChannels();
    final FinalDimensions size = new FinalDimensions(new int[] { w, h, d });
    is3d = (d > 1);
    isMultiChannel = (numSetups > 1);
    // create ImgLoader wrapping the image
    final BasicImgLoader imgLoader;
    if (imp.getStack().isVirtual()) {
        switch(imp.getType()) {
            case ImagePlus.GRAY8:
                imgLoader = VirtualStackImageLoader.createUnsignedByteInstance(imp, setupIdOffset);
                break;
            case ImagePlus.GRAY16:
                imgLoader = VirtualStackImageLoader.createUnsignedShortInstance(imp, setupIdOffset);
                break;
            case ImagePlus.GRAY32:
                imgLoader = VirtualStackImageLoader.createFloatInstance(imp, setupIdOffset);
                break;
            case ImagePlus.COLOR_RGB:
            default:
                imgLoader = VirtualStackImageLoader.createARGBInstance(imp, setupIdOffset);
                break;
        }
    } else {
        switch(imp.getType()) {
            case ImagePlus.GRAY8:
                imgLoader = ImageStackImageLoader.createUnsignedByteInstance(imp, setupIdOffset);
                break;
            case ImagePlus.GRAY16:
                imgLoader = ImageStackImageLoader.createUnsignedShortInstance(imp, setupIdOffset);
                break;
            case ImagePlus.GRAY32:
                imgLoader = ImageStackImageLoader.createFloatInstance(imp, setupIdOffset);
                break;
            case ImagePlus.COLOR_RGB:
            default:
                imgLoader = ImageStackImageLoader.createARGBInstance(imp, setupIdOffset);
                break;
        }
    }
    final File basePath = new File(".");
    // create setups from channels
    final HashMap<Integer, BasicViewSetup> setups = new HashMap<Integer, BasicViewSetup>(numSetups);
    for (int s = 0; s < numSetups; ++s) {
        final int id = setupIdOffset + s;
        final BasicViewSetup setup = new BasicViewSetup(setupIdOffset + s, String.format("%s channel %d", imp.getTitle(), id + 1), size, voxelSize);
        setup.setAttribute(new Channel(id + 1));
        setups.put(id, setup);
        settingsMap.put(id, ColorSettings.fromImagePlus(imp, id, s));
    }
    // create timepoints
    final ArrayList<TimePoint> timepoints = new ArrayList<TimePoint>(numTimepoints);
    for (int t = 0; t < numTimepoints; ++t) timepoints.add(new TimePoint(t));
    // create ViewRegistrations from the images calibration
    final AffineTransform3D sourceTransform = new AffineTransform3D();
    sourceTransform.set(pw, 0, 0, 0, 0, ph, 0, 0, 0, 0, pd, 0);
    final ArrayList<ViewRegistration> registrations = new ArrayList<ViewRegistration>();
    for (int t = 0; t < numTimepoints; ++t) for (int s = 0; s < numSetups; ++s) registrations.add(new ViewRegistration(t, setupIdOffset + s, sourceTransform));
    final SequenceDescriptionMinimal seq = new SequenceDescriptionMinimal(new TimePoints(timepoints), setups, imgLoader, null);
    SpimDataMinimal spimData = new SpimDataMinimal(basePath, seq, new ViewRegistrations(registrations));
    WrapBasicImgLoader.wrapImgLoaderIfNecessary(spimData);
    return spimData;
}
Also used : TimePoints(mpicbg.spim.data.sequence.TimePoints) FinalVoxelDimensions(mpicbg.spim.data.sequence.FinalVoxelDimensions) HashMap(java.util.HashMap) SequenceDescriptionMinimal(bdv.spimdata.SequenceDescriptionMinimal) Channel(mpicbg.spim.data.sequence.Channel) TimePoint(mpicbg.spim.data.sequence.TimePoint) ArrayList(java.util.ArrayList) ViewRegistration(mpicbg.spim.data.registration.ViewRegistration) TimePoint(mpicbg.spim.data.sequence.TimePoint) FinalDimensions(net.imglib2.FinalDimensions) ViewRegistrations(mpicbg.spim.data.registration.ViewRegistrations) SpimDataMinimal(bdv.spimdata.SpimDataMinimal) BasicImgLoader(mpicbg.spim.data.generic.sequence.BasicImgLoader) WrapBasicImgLoader(bdv.spimdata.WrapBasicImgLoader) File(java.io.File) BasicViewSetup(mpicbg.spim.data.generic.sequence.BasicViewSetup) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Aggregations

SpimDataMinimal (bdv.spimdata.SpimDataMinimal)17 XmlIoSpimDataMinimal (bdv.spimdata.XmlIoSpimDataMinimal)11 File (java.io.File)8 ArrayList (java.util.ArrayList)7 ViewRegistration (mpicbg.spim.data.registration.ViewRegistration)7 SequenceDescriptionMinimal (bdv.spimdata.SequenceDescriptionMinimal)6 BasicViewSetup (mpicbg.spim.data.generic.sequence.BasicViewSetup)6 ViewRegistrations (mpicbg.spim.data.registration.ViewRegistrations)6 TimePoint (mpicbg.spim.data.sequence.TimePoint)6 SpimDataException (mpicbg.spim.data.SpimDataException)5 FinalVoxelDimensions (mpicbg.spim.data.sequence.FinalVoxelDimensions)5 TimePoints (mpicbg.spim.data.sequence.TimePoints)5 AffineTransform3D (net.imglib2.realtransform.AffineTransform3D)5 Hdf5ImageLoader (bdv.img.hdf5.Hdf5ImageLoader)4 HashMap (java.util.HashMap)4 Channel (mpicbg.spim.data.sequence.Channel)4 FinalDimensions (net.imglib2.FinalDimensions)4 FloatType (net.imglib2.type.numeric.real.FloatType)4 BdvHandle (bdv.util.BdvHandle)3 BdvStackSource (bdv.util.BdvStackSource)3