Search in sources :

Example 1 with N5Reader

use of org.janelia.saalfeldlab.n5.N5Reader in project bigwarp by saalfeldlab.

the class BigWarpInit method loadN5Source.

public static Source<?> loadN5Source(final String n5Root, final String n5Dataset) {
    final N5Reader n5;
    try {
        n5 = new N5Factory().openReader(n5Root);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    final N5MetadataParser<?>[] PARSERS = new N5MetadataParser[] { new ImagePlusLegacyMetadataParser(), new N5CosemMetadataParser(), new N5SingleScaleMetadataParser(), new CanonicalMetadataParser(), new N5GenericSingleScaleMetadataParser() };
    final N5MetadataParser<?>[] GROUP_PARSERS = new N5MetadataParser[] { new N5CosemMultiScaleMetadata.CosemMultiScaleParser(), new N5ViewerMultiscaleMetadataParser(), new CanonicalMetadataParser() };
    N5Metadata meta = null;
    try {
        final N5DatasetDiscoverer discoverer = new N5DatasetDiscoverer(n5, N5DatasetDiscoverer.fromParsers(PARSERS), N5DatasetDiscoverer.fromParsers(GROUP_PARSERS));
        final N5TreeNode node = discoverer.discoverAndParseRecursive(n5Dataset);
        meta = node.getMetadata();
    } catch (IOException e) {
    }
    if (meta instanceof MultiscaleMetadata) {
        return openAsSourceMulti(n5, (MultiscaleMetadata<?>) meta, true);
    } else {
        return openAsSource(n5, meta, true);
    }
}
Also used : N5DatasetDiscoverer(org.janelia.saalfeldlab.n5.N5DatasetDiscoverer) ImagePlusLegacyMetadataParser(org.janelia.saalfeldlab.n5.metadata.imagej.ImagePlusLegacyMetadataParser) N5ViewerMultiscaleMetadataParser(org.janelia.saalfeldlab.n5.metadata.N5ViewerMultiscaleMetadataParser) N5Metadata(org.janelia.saalfeldlab.n5.metadata.N5Metadata) N5TreeNode(org.janelia.saalfeldlab.n5.N5TreeNode) N5MetadataParser(org.janelia.saalfeldlab.n5.metadata.N5MetadataParser) MultiscaleMetadata(org.janelia.saalfeldlab.n5.metadata.MultiscaleMetadata) IOException(java.io.IOException) N5CosemMetadataParser(org.janelia.saalfeldlab.n5.metadata.N5CosemMetadataParser) N5SingleScaleMetadataParser(org.janelia.saalfeldlab.n5.metadata.N5SingleScaleMetadataParser) N5GenericSingleScaleMetadataParser(org.janelia.saalfeldlab.n5.metadata.N5GenericSingleScaleMetadataParser) N5Factory(org.janelia.saalfeldlab.n5.ij.N5Factory) N5Reader(org.janelia.saalfeldlab.n5.N5Reader) CanonicalMetadataParser(org.janelia.saalfeldlab.n5.metadata.canonical.CanonicalMetadataParser)

Example 2 with N5Reader

use of org.janelia.saalfeldlab.n5.N5Reader in project bigwarp by saalfeldlab.

the class BigWarpInit method openAsSource.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T extends N5Metadata> Source<?> openAsSource(final N5Reader n5, final T meta, final boolean isVolatile) {
    final RandomAccessibleInterval imageRaw;
    final RandomAccessibleInterval image;
    try {
        if (isVolatile)
            imageRaw = to3d(N5Utils.openVolatile(n5, meta.getPath()));
        else
            imageRaw = to3d(N5Utils.open(n5, meta.getPath()));
        if (meta instanceof N5ImagePlusMetadata && ((N5ImagePlusMetadata) meta).getType() == ImagePlus.COLOR_RGB && Util.getTypeFromInterval(imageRaw) instanceof UnsignedIntType) {
            image = toColor(imageRaw);
        } else
            image = imageRaw;
        if (meta instanceof SpatialMetadata) {
            final String unit = ((SpatialMetadata) meta).unit();
            final AffineTransform3D srcXfm = ((SpatialMetadata) meta).spatialTransform3d();
            final FinalVoxelDimensions voxelDims = new FinalVoxelDimensions(unit, new double[] { srcXfm.get(0, 0), srcXfm.get(1, 1), srcXfm.get(2, 2) });
            return new BwRandomAccessibleIntervalSource(image, Util.getTypeFromInterval(image), srcXfm, meta.getPath(), voxelDims);
        } else
            return new BwRandomAccessibleIntervalSource(image, Util.getTypeFromInterval(image), new AffineTransform3D(), meta.getPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : N5ImagePlusMetadata(org.janelia.saalfeldlab.n5.metadata.imagej.N5ImagePlusMetadata) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) SpatialMetadata(org.janelia.saalfeldlab.n5.metadata.SpatialMetadata) FinalVoxelDimensions(mpicbg.spim.data.sequence.FinalVoxelDimensions) BwRandomAccessibleIntervalSource(bdv.img.BwRandomAccessibleIntervalSource) UnsignedIntType(net.imglib2.type.numeric.integer.UnsignedIntType) IOException(java.io.IOException) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Example 3 with N5Reader

use of org.janelia.saalfeldlab.n5.N5Reader in project mars-fx by duderstadt-lab.

the class MarsBdvFrame method loadN5Source.

private Source<T> loadN5Source(MarsBdvSource source, MarsMetadata meta) throws IOException {
    N5Reader reader;
    if (n5Readers.containsKey(source.getPath())) {
        reader = n5Readers.get(source.getPath());
    } else {
        reader = new N5Importer.N5ViewerReaderFun().apply(source.getPath());
        n5Readers.put(source.getPath(), reader);
    }
    @SuppressWarnings("rawtypes") final RandomAccessibleInterval wholeImage = N5Utils.open(reader, source.getN5Dataset());
    // wholeImage should be XYT or XYCT. If XYCT, we hyperSlice to get one
    // channel.
    // XYZCT should also be supported
    int dims = wholeImage.numDimensions();
    @SuppressWarnings("rawtypes") final RandomAccessibleInterval image = (dims > 3) ? Views.hyperSlice(wholeImage, wholeImage.numDimensions() - 2, source.getChannel()) : wholeImage;
    int tSize = (int) image.dimension(image.numDimensions() - 1);
    if (tSize > numTimePoints)
        numTimePoints = tSize;
    @SuppressWarnings("rawtypes") final RandomAccessibleInterval[] images = new RandomAccessibleInterval[1];
    images[0] = image;
    if (source.getSingleTimePointMode()) {
        AffineTransform3D[] transforms = new AffineTransform3D[tSize];
        // Drift should be corrected against them
        for (int t = 0; t < tSize; t++) transforms[t] = source.getAffineTransform3D();
        int singleTimePoint = source.getSingleTimePoint();
        @SuppressWarnings("unchecked") final MarsSingleTimePointN5Source<T> n5Source = new MarsSingleTimePointN5Source<>((T) Util.getTypeFromInterval(image), source.getName(), images, transforms, singleTimePoint);
        return n5Source;
    } else {
        AffineTransform3D[] transforms = new AffineTransform3D[tSize];
        for (int t = 0; t < tSize; t++) {
            if (source.getCorrectDrift()) {
                double dX = meta.getPlane(0, 0, 0, t).getXDrift();
                double dY = meta.getPlane(0, 0, 0, t).getYDrift();
                transforms[t] = source.getAffineTransform3D(dX, dY);
            } else
                transforms[t] = source.getAffineTransform3D();
        }
        @SuppressWarnings("unchecked") final MarsN5Source<T> n5Source = new MarsN5Source<>((T) Util.getTypeFromInterval(image), source.getName(), images, transforms);
        return n5Source;
    }
}
Also used : RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) N5Reader(org.janelia.saalfeldlab.n5.N5Reader) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Example 4 with N5Reader

use of org.janelia.saalfeldlab.n5.N5Reader in project mars-fx by duderstadt-lab.

the class MarsBdvFrame method loadN5VolatileSource.

private Source<T> loadN5VolatileSource(MarsBdvSource source, MarsMetadata meta) throws IOException {
    N5Reader reader;
    if (n5Readers.containsKey(source.getPath())) {
        reader = n5Readers.get(source.getPath());
    } else {
        reader = new N5Importer.N5ViewerReaderFun().apply(source.getPath());
        n5Readers.put(source.getPath(), reader);
    }
    @SuppressWarnings("rawtypes") final RandomAccessibleInterval wholeImage = N5Utils.openVolatile(reader, source.getN5Dataset());
    // wholeImage should be XYT or XYCT. If XYCT, we hyperSlice to get one
    // channel.
    // XYZCT should also be supported
    int dims = wholeImage.numDimensions();
    @SuppressWarnings("rawtypes") final RandomAccessibleInterval image = (dims > 3) ? Views.hyperSlice(wholeImage, wholeImage.numDimensions() - 2, source.getChannel()) : wholeImage;
    int tSize = (int) image.dimension(image.numDimensions() - 1);
    if (tSize > numTimePoints)
        numTimePoints = tSize;
    @SuppressWarnings("rawtypes") final RandomAccessibleInterval[] images = new RandomAccessibleInterval[1];
    images[0] = image;
    if (source.getSingleTimePointMode()) {
        AffineTransform3D[] transforms = new AffineTransform3D[tSize];
        // Drift should be corrected against them
        for (int t = 0; t < tSize; t++) transforms[t] = source.getAffineTransform3D();
        int singleTimePoint = source.getSingleTimePoint();
        @SuppressWarnings("unchecked") final MarsSingleTimePointN5Source<T> n5Source = new MarsSingleTimePointN5Source<>((T) Util.getTypeFromInterval(image), source.getName(), images, transforms, singleTimePoint);
        return (Source<T>) n5Source.asVolatile(sharedQueue);
    } else {
        AffineTransform3D[] transforms = new AffineTransform3D[tSize];
        for (int t = 0; t < tSize; t++) {
            if (source.getCorrectDrift()) {
                double dX = meta.getPlane(0, 0, 0, t).getXDrift();
                double dY = meta.getPlane(0, 0, 0, t).getYDrift();
                transforms[t] = source.getAffineTransform3D(dX, dY);
            } else
                transforms[t] = source.getAffineTransform3D();
        }
        @SuppressWarnings("unchecked") final MarsN5Source<T> n5Source = new MarsN5Source<>((T) Util.getTypeFromInterval(image), source.getName(), images, transforms);
        return (Source<T>) n5Source.asVolatile(sharedQueue);
    }
}
Also used : Source(bdv.viewer.Source) SpimSource(bdv.SpimSource) MarsBdvSource(de.mpg.biochem.mars.metadata.MarsBdvSource) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) N5Reader(org.janelia.saalfeldlab.n5.N5Reader) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Aggregations

RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)3 AffineTransform3D (net.imglib2.realtransform.AffineTransform3D)3 N5Reader (org.janelia.saalfeldlab.n5.N5Reader)3 IOException (java.io.IOException)2 SpimSource (bdv.SpimSource)1 BwRandomAccessibleIntervalSource (bdv.img.BwRandomAccessibleIntervalSource)1 Source (bdv.viewer.Source)1 MarsBdvSource (de.mpg.biochem.mars.metadata.MarsBdvSource)1 FinalVoxelDimensions (mpicbg.spim.data.sequence.FinalVoxelDimensions)1 UnsignedIntType (net.imglib2.type.numeric.integer.UnsignedIntType)1 N5DatasetDiscoverer (org.janelia.saalfeldlab.n5.N5DatasetDiscoverer)1 N5TreeNode (org.janelia.saalfeldlab.n5.N5TreeNode)1 N5Factory (org.janelia.saalfeldlab.n5.ij.N5Factory)1 MultiscaleMetadata (org.janelia.saalfeldlab.n5.metadata.MultiscaleMetadata)1 N5CosemMetadataParser (org.janelia.saalfeldlab.n5.metadata.N5CosemMetadataParser)1 N5GenericSingleScaleMetadataParser (org.janelia.saalfeldlab.n5.metadata.N5GenericSingleScaleMetadataParser)1 N5Metadata (org.janelia.saalfeldlab.n5.metadata.N5Metadata)1 N5MetadataParser (org.janelia.saalfeldlab.n5.metadata.N5MetadataParser)1 N5SingleScaleMetadataParser (org.janelia.saalfeldlab.n5.metadata.N5SingleScaleMetadataParser)1 N5ViewerMultiscaleMetadataParser (org.janelia.saalfeldlab.n5.metadata.N5ViewerMultiscaleMetadataParser)1