From d4d704655c5fd8633104a7a382b36c25f2765a65 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Mon, 11 Nov 2024 16:20:57 -0500 Subject: [PATCH] continuing with OME-ZARR support --- .../spimdata/imgloaders/OMEZarrAttibutes.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/OMEZarrAttibutes.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/OMEZarrAttibutes.java index 1bacd957..99bd737b 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/OMEZarrAttibutes.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/OMEZarrAttibutes.java @@ -23,16 +23,84 @@ package net.preibisch.mvrecon.fiji.spimdata.imgloaders; import java.net.URI; +import java.util.function.Function; +import org.janelia.saalfeldlab.n5.DatasetAttributes; import org.janelia.saalfeldlab.n5.N5Reader; import org.janelia.saalfeldlab.n5.universe.N5Factory.StorageFormat; +import org.janelia.saalfeldlab.n5.universe.metadata.axes.Axis; import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata; import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata.OmeNgffDataset; +import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata.OmeNgffDownsamplingMetadata; +import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformation; +import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.ScaleCoordinateTransformation; +import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.TranslationCoordinateTransformation; +import net.imglib2.realtransform.AffineTransform3D; import util.URITools; public class OMEZarrAttibutes { + /** + * + * @param n - num dimensions, 3-5 makes sense here (zyx to tczyx; TODO: which order?) + * @param numResolutionLevels - number of multiresolution levels (e.g. s0, s1, s2 would be 3), always includes full res + * @return + */ + public static OmeNgffMultiScaleMetadata[] createOMEZarrMetadata( + final int n, + final int numResolutionLevels, + final Function levelToName, + final Function levelToMipmapTransform ) + { + final OmeNgffMultiScaleMetadata[] meta = new OmeNgffMultiScaleMetadata[ 1 ]; + + // dataset name + final String path = null; + final String name = "setup0_timepoint5"; // I also saw "/" + final String type = null; + + // axis descriptions + // TODO: for some reason they are in TCZYX order + final Axis[] axes = new Axis[ n ]; + + int index = 0; + + if ( n >= 5 ) + axes[ index++ ] = new Axis( "time", "t", "millisecond" ); + + if ( n >= 4 ) + axes[ index++ ] = new Axis( "channel", "c", null ); + + axes[ index++ ] = new Axis( "space", "z", "micrometer" ); + axes[ index++ ] = new Axis( "space", "y", "micrometer" ); + axes[ index++ ] = new Axis( "space", "x", "micrometer" ); + + // multiresolution-pyramid + // TODO: for some reason in XYZCT order (but in the file it seems reversed) + final OmeNgffDataset[] datasets = new OmeNgffDataset[ numResolutionLevels ]; + + for ( int s = 0; s < numResolutionLevels; ++s ) + { + datasets[ s ] = new OmeNgffDataset(); + + datasets[ s ].path = levelToName.apply( s ); + + datasets[ s ].coordinateTransformations = new CoordinateTransformation[ 2 ]; + datasets[ s ].coordinateTransformations[ 0 ] = new ScaleCoordinateTransformation( new double[] { } ); // TODO + datasets[ s ].coordinateTransformations[ 1 ] = new TranslationCoordinateTransformation( new double[] { } ); // TODO + } + + // just saw these being null everywhere + final DatasetAttributes[] childrenAttributes = null; + final CoordinateTransformation[] coordinateTransformations = null; // I also saw ScaleTransform [1,1,1] + final OmeNgffDownsamplingMetadata metadata = null; + + meta[ 0 ] = new OmeNgffMultiScaleMetadata( n, path, name, type, "0.4", axes, datasets, childrenAttributes, coordinateTransformations, metadata ); + + return meta; + } + public static void loadOMEZarr( final N5Reader n5, final String dataset ) { //org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMetadata @@ -60,6 +128,9 @@ public static void loadOMEZarr( final N5Reader n5, final String dataset ) public static void main( String[] args ) { + //final URI uri = URITools.toURI( "https://storage.googleapis.com/jax-public-ngff/KOMP/adult_lacZ/ndp/Moxd1/23420_K35061_FGut.zarr/0/" ); + //final String dataset = "/"; + final URI uri = URITools.toURI( "s3://aind-open-data/exaSPIM_708373_2024-04-02_19-49-38/SPIM.ome.zarr/" ); final String dataset = "tile_x_0001_y_0001_z_0000_ch_488.zarr";