From c6b5c64bf5c8e037c46317bcf93ae7fc50adf333 Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Thu, 18 Jul 2024 10:27:53 +0200 Subject: [PATCH] Implement TIFF folder opening --- .../org/embl/mobie/io/ImageDataFormat.java | 4 ++ .../mobie/io/imagedata/TIFFImageData.java | 16 ++++++- src/test/java/develop/FolderOpenerTest.java | 43 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/java/develop/FolderOpenerTest.java diff --git a/src/main/java/org/embl/mobie/io/ImageDataFormat.java b/src/main/java/org/embl/mobie/io/ImageDataFormat.java index 9488a48..087a0fc 100644 --- a/src/main/java/org/embl/mobie/io/ImageDataFormat.java +++ b/src/main/java/org/embl/mobie/io/ImageDataFormat.java @@ -30,6 +30,8 @@ import com.google.gson.annotations.SerializedName; +import java.io.File; + import static org.embl.mobie.io.ImageDataFormat.Names.*; /** @@ -198,6 +200,8 @@ public static ImageDataFormat fromPath(String path) final String lowerCase = path.toLowerCase(); if(lowerCase.contains( ".zarr" )) return ImageDataFormat.OmeZarr; + else if (new File(path).isDirectory()) + return ImageDataFormat.Tiff; // assume TIFF image sequence else if (lowerCase.endsWith( ".xml" )) return ImageDataFormat.Bdv; // TODO: https://github.com/mobie/mobie-io/issues/131 else if (lowerCase.endsWith( ".ome.tif" ) || lowerCase.endsWith( ".ome.tiff" ) ) diff --git a/src/main/java/org/embl/mobie/io/imagedata/TIFFImageData.java b/src/main/java/org/embl/mobie/io/imagedata/TIFFImageData.java index ad67252..a726af9 100644 --- a/src/main/java/org/embl/mobie/io/imagedata/TIFFImageData.java +++ b/src/main/java/org/embl/mobie/io/imagedata/TIFFImageData.java @@ -4,12 +4,15 @@ import ch.epfl.biop.bdv.img.imageplus.ImagePlusToSpimData; import ij.IJ; import ij.ImagePlus; +import ij.plugin.FolderOpener; import mpicbg.spim.data.SpimData; import mpicbg.spim.data.generic.AbstractSpimData; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.NumericType; import org.embl.mobie.io.util.IOHelper; +import java.io.File; + public class TIFFImageData< T extends NumericType< T > & NativeType< T > > extends SpimDataImageData< T > { public TIFFImageData( String uri, SharedQueue sharedQueue ) @@ -19,7 +22,18 @@ public TIFFImageData( String uri, SharedQueue sharedQueue ) @Override public AbstractSpimData< ? > open( String uri ) { - ImagePlus imagePlus = IJ.openVirtual( uri ); + ImagePlus imagePlus; + if ( new File( uri ).isDirectory() ) + { + imagePlus = FolderOpener.open( + uri, + "virtual filter=(.*.tif.*)"); + } + else + { + imagePlus = IJ.openVirtual( uri ); + } + //ImagePlus imagePlus = IOHelper.openTiffFromFile( uri ); return ImagePlusToSpimData.getSpimData( imagePlus ); } diff --git a/src/test/java/develop/FolderOpenerTest.java b/src/test/java/develop/FolderOpenerTest.java new file mode 100644 index 0000000..f188849 --- /dev/null +++ b/src/test/java/develop/FolderOpenerTest.java @@ -0,0 +1,43 @@ +package develop; + +import bdv.cache.SharedQueue; +import bdv.util.BdvFunctions; +import bdv.viewer.Source; +import ij.ImagePlus; +import ij.plugin.FolderOpener; +import net.imglib2.Volatile; +import net.imglib2.type.NativeType; +import net.imglib2.type.numeric.NumericType; +import net.imglib2.util.Pair; +import org.embl.mobie.io.ImageDataFormat; +import org.embl.mobie.io.ImageDataOpener; +import org.embl.mobie.io.imagedata.ImageData; +import org.embl.mobie.io.imagedata.TIFFImageData; + +import java.io.File; +import java.util.Arrays; + +public class FolderOpenerTest +{ + public static < T extends NumericType< T > & NativeType< T > > void main( String[] args ) + { + + String path = "/Users/tischer/Documents/mobie-viewer-fiji/src/test/resources/collections/mri-stack/"; + + path = "/Volumes/emcf/ronchi/MRC-MM/aligned/G0"; +// ImagePlus imp = FolderOpener.open( +// path, +// "virtual filter=(.*.tif.*)"); +// imp.show(); + + ImageData< T > imageData = ImageDataOpener.open( path ); + Pair< Source< T >, Source< ? extends Volatile< T > > > sourcePair = imageData.getSourcePair( 0 ); + + BdvFunctions.show( sourcePair.getB() ); + +// boolean directory = new File( "https://sgsdfgdsf/sfsgd" ).isDirectory(); +// TIFFImageData< ? > imageData = new TIFFImageData<>( path, new SharedQueue( 1 ) ); +// Source< ? > source = imageData.getSourcePair( 0 ).getA(); +// System.out.println( Arrays.toString( source.getSource( 0,0 ).dimensionsAsLongArray() ) ); + } +}