Skip to content

Commit

Permalink
Implement TIFF folder opening
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jul 18, 2024
1 parent e44dd50 commit c6b5c64
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/org/embl/mobie/io/ImageDataFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import com.google.gson.annotations.SerializedName;

import java.io.File;

import static org.embl.mobie.io.ImageDataFormat.Names.*;

/**
Expand Down Expand Up @@ -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" ) )
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/embl/mobie/io/imagedata/TIFFImageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 );
}
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/develop/FolderOpenerTest.java
Original file line number Diff line number Diff line change
@@ -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() ) );
}
}

0 comments on commit c6b5c64

Please sign in to comment.