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);
}
}
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;
}
Aggregations