From eedee2a103b289e9787bf14f4615527c01ccc01c Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Fri, 7 Jun 2024 16:30:42 +0200 Subject: [PATCH] Improve opening OME-Zarr files as a grid view --- src/main/java/org/embl/mobie/MoBIE.java | 2 +- .../open/OpenImageAndLabelsFilesCommand.java | 12 ++++--- .../open/OpenImageAndLabelsURIsCommand.java | 5 +-- ...enMultipleImagesAndLabelsFilesCommand.java | 5 +-- ...penMultipleImagesAndLabelsURIsCommand.java | 5 +-- .../mobie/command/open/OpenTableCommand.java | 5 ++- .../embl/mobie/lib/bdv/view/SliceViewer.java | 1 + .../mobie/lib/files/ImageFileSources.java | 9 ++++- .../embl/mobie/lib/source/SourceHelper.java | 1 + src/test/java/develop/OpenAutoMicTable.java | 1 - .../java/projects/OpenLocalYannickZarrs.java} | 36 +++++++++++-------- .../OpenTeresaData.java | 1 - 12 files changed, 53 insertions(+), 30 deletions(-) rename src/{main/java/org/embl/mobie/command/open/OpenTableAdvancedCommand.java => test/java/projects/OpenLocalYannickZarrs.java} (60%) diff --git a/src/main/java/org/embl/mobie/MoBIE.java b/src/main/java/org/embl/mobie/MoBIE.java index 94bcdf4d..570c068f 100644 --- a/src/main/java/org/embl/mobie/MoBIE.java +++ b/src/main/java/org/embl/mobie/MoBIE.java @@ -89,7 +89,7 @@ public class MoBIE new Thread(() -> { long start = System.currentTimeMillis(); AmazonS3ClientBuilder.standard(); - IJ.log( "Initialised AmazonS3ClientBuilder in " + ( System.currentTimeMillis() -start ) + " ms." ); + IJ.log( "( Initialised AmazonS3ClientBuilder in " + ( System.currentTimeMillis() -start ) + " ms. )" ); }).start(); } diff --git a/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsFilesCommand.java b/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsFilesCommand.java index fb95e64c..97f89231 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsFilesCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsFilesCommand.java @@ -46,10 +46,11 @@ public class OpenImageAndLabelsFilesCommand implements Command { static { net.imagej.patcher.LegacyInjector.preinit(); } - @Parameter( label = "Image Path", required = false ) + // FIXME: https://forum.image.sc/t/scijava-ui-open-both-file-and-directory/97389 + @Parameter( label = "Image Path", style = "both", required = false ) public File image; - @Parameter( label = "Label Mask Path", required = false ) + @Parameter( label = "Label Mask Path", style = "both", required = false ) public File labels; @Parameter( label = "Label Mask Table Path", required = false ) @@ -58,13 +59,14 @@ public class OpenImageAndLabelsFilesCommand implements Command { @Parameter( label = "Spatial Calibration" ) public SpatialCalibration spatialCalibration = SpatialCalibration.FromImage; + @Parameter( label = "Grid type", description = "If the images are different and not too many, use Transformed; otherwise use Stitched for better performance.") + public GridType gridType = GridType.Transformed; + @Override public void run() { final MoBIESettings settings = new MoBIESettings(); - final GridType gridType = GridType.Stitched; // TODO: fetch from UI - final ArrayList< String > imageList = new ArrayList<>(); if ( image != null ) imageList.add( image.getAbsolutePath() ); @@ -85,7 +87,7 @@ public void run() } catch ( IOException e ) { - e.printStackTrace(); + throw new RuntimeException( e ); } } diff --git a/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsURIsCommand.java b/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsURIsCommand.java index 34083a1b..a2c5a63c 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsURIsCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsURIsCommand.java @@ -57,13 +57,14 @@ public class OpenImageAndLabelsURIsCommand implements Command { @Parameter( label = "Spatial Calibration" ) public SpatialCalibration spatialCalibration = SpatialCalibration.FromImage; + @Parameter( label = "Grid type", description = "If the images are different and not too many, use Transformed; otherwise use Stitched for better performance.") + public GridType gridType = GridType.Transformed; + @Override public void run() { final MoBIESettings settings = new MoBIESettings(); - final GridType gridType = GridType.Stitched; // TODO: maybe fetch from UI - final ArrayList< String > imageList = new ArrayList<>(); if ( image != null ) imageList.add( image ); diff --git a/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsFilesCommand.java b/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsFilesCommand.java index 670ab7a6..44b87ea0 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsFilesCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsFilesCommand.java @@ -73,13 +73,14 @@ public class OpenMultipleImagesAndLabelsFilesCommand implements Command { @Parameter( label = "Spatial Calibration" ) public SpatialCalibration spatialCalibration = SpatialCalibration.FromImage; + @Parameter( label = "Grid type", description = "If the images are different and not too many, use Transformed; otherwise use Stitched for better performance.") + public GridType gridType = GridType.Transformed; + @Override public void run() { final MoBIESettings settings = new MoBIESettings(); - final GridType gridType = GridType.Stitched; // TODO: fetch from UI - final ArrayList< String > imageList = new ArrayList<>(); if ( image0 != null ) imageList.add( image0.getAbsolutePath() ); if ( image1 != null ) imageList.add( image1.getAbsolutePath() ); diff --git a/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsURIsCommand.java b/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsURIsCommand.java index 7768c94a..588db033 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsURIsCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsURIsCommand.java @@ -72,13 +72,14 @@ public class OpenMultipleImagesAndLabelsURIsCommand implements Command { @Parameter( label = "Spatial Calibration" ) public SpatialCalibration spatialCalibration = SpatialCalibration.FromImage; + @Parameter( label = "Grid type", description = "If the images are different and not too many, use Transformed; otherwise use Stitched for better performance.") + public GridType gridType = GridType.Transformed; + @Override public void run() { final MoBIESettings settings = new MoBIESettings(); - final GridType gridType = GridType.Stitched; // TODO: fetch from UI - final ArrayList< String > imageList = new ArrayList<>(); if ( image0 != null ) imageList.add( image0 ); if ( image1 != null ) imageList.add( image1 ); diff --git a/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java b/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java index 9644d326..b762cedd 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java @@ -74,10 +74,13 @@ public class OpenTableCommand implements Command { @Parameter( label = "Spatial Calibration" ) public SpatialCalibration spatialCalibration = SpatialCalibration.FromImage; + @Parameter( label = "Grid type", description = "If the images are different and not too many, use \"Transformed\"; otherwise use \"Stitched\" for better performance.") + public GridType gridType = GridType.Transformed; + @Override public void run() { - run( GridType.Stitched ); + run( gridType ); } public void run( GridType gridType ) diff --git a/src/main/java/org/embl/mobie/lib/bdv/view/SliceViewer.java b/src/main/java/org/embl/mobie/lib/bdv/view/SliceViewer.java index 4cb12f34..20136035 100644 --- a/src/main/java/org/embl/mobie/lib/bdv/view/SliceViewer.java +++ b/src/main/java/org/embl/mobie/lib/bdv/view/SliceViewer.java @@ -205,6 +205,7 @@ public static BdvHandle createBdv( boolean is2D, String frameTitle ) final MobieSerializableBdvOptions sOptions = new MobieSerializableBdvOptions(); sOptions.is2D = is2D; sOptions.frameTitle = frameTitle; + sOptions.interpolate = !is2D; IBdvSupplier bdvSupplier = new MobieBdvSupplier( sOptions ); //SourceAndConverterServices.getBdvDisplayService().setDefaultBdvSupplier( bdvSupplier ); //BdvHandle bdvHandle = SourceAndConverterServices.getBdvDisplayService().getNewBdv(); diff --git a/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java b/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java index 6db5c7c1..edbf0cd1 100644 --- a/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java +++ b/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java @@ -31,9 +31,11 @@ import bdv.viewer.Source; import ij.IJ; import loci.formats.in.CellSensReader; +import net.imglib2.RandomAccessibleInterval; import net.imglib2.Volatile; import net.imglib2.realtransform.AffineTransform3D; import org.apache.commons.io.FilenameUtils; +import org.embl.mobie.MoBIE; import org.embl.mobie.io.ImageDataOpener; import org.embl.mobie.io.imagedata.ImageData; import org.embl.mobie.io.util.IOHelper; @@ -169,12 +171,17 @@ protected static boolean isCellProfilerColumn( String column, Table table ) private void setMetadata( Integer channelIndex ) { metadataSource = nameToFullPath.keySet().iterator().next(); + IJ.log( "Fetching metadata from " + nameToFullPath.get( metadataSource ) ); ImageData< ? > imageData = ImageDataOpener.open( nameToFullPath.get( metadataSource ) ); CanonicalDatasetMetadata canonicalDatasetMetadata = imageData.getMetadata( channelIndex ); metadata = new Metadata( canonicalDatasetMetadata ); - Source< ? extends Volatile< ? > > source = imageData.getSourcePair( channelIndex ).getB(); + Source< ? > source = imageData.getSourcePair( channelIndex ).getA(); metadata.numZSlices = (int) source.getSource( 0, 0 ).dimension( 2 ); metadata.numTimePoints = SourceHelper.getNumTimePoints( source ); + metadata.contrastLimits = MoBIEHelper.computeMinMax( ( RandomAccessibleInterval ) source.getSource( 0, source.getNumMipmapLevels() -1 ) ); + IJ.log( "Slices: " + metadata.numZSlices ); + IJ.log( "Frames: " + metadata.numTimePoints ); + IJ.log( "Min, max: " + Arrays.toString( metadata.contrastLimits ) ); } private static String applyPathMapping( String pathMapping, String path ) diff --git a/src/main/java/org/embl/mobie/lib/source/SourceHelper.java b/src/main/java/org/embl/mobie/lib/source/SourceHelper.java index 80e05daa..6ab75992 100644 --- a/src/main/java/org/embl/mobie/lib/source/SourceHelper.java +++ b/src/main/java/org/embl/mobie/lib/source/SourceHelper.java @@ -105,6 +105,7 @@ public static int getNumTimePoints( Source< ? > source ) if ( numSourceTimepoints == maxNumTimePoints ) { System.err.println( source.getName() + " has more than " + maxNumTimePoints + " time-points. Is this an error?!" ); + return 1; } return numSourceTimepoints; diff --git a/src/test/java/develop/OpenAutoMicTable.java b/src/test/java/develop/OpenAutoMicTable.java index 5050ee09..6340cfa2 100644 --- a/src/test/java/develop/OpenAutoMicTable.java +++ b/src/test/java/develop/OpenAutoMicTable.java @@ -29,7 +29,6 @@ package develop; import net.imagej.ImageJ; -import org.embl.mobie.command.open.OpenTableAdvancedCommand; import org.embl.mobie.lib.transform.GridType; import java.io.File; diff --git a/src/main/java/org/embl/mobie/command/open/OpenTableAdvancedCommand.java b/src/test/java/projects/OpenLocalYannickZarrs.java similarity index 60% rename from src/main/java/org/embl/mobie/command/open/OpenTableAdvancedCommand.java rename to src/test/java/projects/OpenLocalYannickZarrs.java index 7910d187..e859919a 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenTableAdvancedCommand.java +++ b/src/test/java/projects/OpenLocalYannickZarrs.java @@ -26,25 +26,33 @@ * POSSIBILITY OF SUCH DAMAGE. * #L% */ -package org.embl.mobie.command.open; +package projects; -import org.embl.mobie.command.CommandConstants; +import net.imagej.ImageJ; +import org.embl.mobie.MoBIE; +import org.embl.mobie.MoBIESettings; +import org.embl.mobie.command.open.OpenImageAndLabelsFilesCommand; import org.embl.mobie.lib.transform.GridType; -import org.scijava.command.Command; -import org.scijava.plugin.Parameter; -import org.scijava.plugin.Plugin; -@Plugin(type = Command.class, menuPath = CommandConstants.MOBIE_PLUGIN_OPEN + "Open Table (Advanced)..." ) -public class OpenTableAdvancedCommand extends OpenTableCommand { +import java.io.File; +import java.io.IOException; - static { net.imagej.patcher.LegacyInjector.preinit(); } +public class OpenLocalYannickZarrs +{ + public static void main( String[] args ) throws IOException + { + final ImageJ imageJ = new ImageJ(); + imageJ.ui().showUI(); - @Parameter( label = "Grid type" ) - public GridType gridType = GridType.Transformed; + OpenImageAndLabelsFilesCommand command = new OpenImageAndLabelsFilesCommand(); + command.gridType = GridType.Transformed; + command.image = new File("/Volumes/schwab/schwab/MoBIE-GRIDtestJUNE2024/JEOL1400_20240426/.*.ome.zarr"); + //command.image = new File("/Volumes/schwab/schwab/MoBIE-GRIDtestJUNE2024/JEOL1400_20240426/Alex_ASH_BlockA1_Grid11_PS_ser1_cell4_8k_blend.ome.zarr"); - @Override - public void run() - { - super.run( gridType ); + // FIXME + // - why does the software complain that there are more than 1000 time-points? + // - add the relative paths to the table + // - add the full paths to the table + command.run(); } } diff --git a/src/test/java/projects/muscle_patterning_drosophila/OpenTeresaData.java b/src/test/java/projects/muscle_patterning_drosophila/OpenTeresaData.java index c95bcd2b..35344ba4 100644 --- a/src/test/java/projects/muscle_patterning_drosophila/OpenTeresaData.java +++ b/src/test/java/projects/muscle_patterning_drosophila/OpenTeresaData.java @@ -29,7 +29,6 @@ package projects.muscle_patterning_drosophila; import net.imagej.ImageJ; -import org.embl.mobie.command.open.OpenTableAdvancedCommand; import org.embl.mobie.lib.transform.GridType; import java.io.File;