Search in sources :

Example 1 with N5Metadata

use of org.janelia.saalfeldlab.n5.metadata.N5Metadata 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 N5Metadata

use of org.janelia.saalfeldlab.n5.metadata.N5Metadata 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)

Aggregations

IOException (java.io.IOException)2 BwRandomAccessibleIntervalSource (bdv.img.BwRandomAccessibleIntervalSource)1 FinalVoxelDimensions (mpicbg.spim.data.sequence.FinalVoxelDimensions)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 AffineTransform3D (net.imglib2.realtransform.AffineTransform3D)1 UnsignedIntType (net.imglib2.type.numeric.integer.UnsignedIntType)1 N5DatasetDiscoverer (org.janelia.saalfeldlab.n5.N5DatasetDiscoverer)1 N5Reader (org.janelia.saalfeldlab.n5.N5Reader)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 SpatialMetadata (org.janelia.saalfeldlab.n5.metadata.SpatialMetadata)1 CanonicalMetadataParser (org.janelia.saalfeldlab.n5.metadata.canonical.CanonicalMetadataParser)1 ImagePlusLegacyMetadataParser (org.janelia.saalfeldlab.n5.metadata.imagej.ImagePlusLegacyMetadataParser)1