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