Skip to content

Commit

Permalink
Fixes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Mar 15, 2024
1 parent 0216a25 commit 33e5d25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions src/main/java/org/embl/mobie/io/CachedCellImgOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -92,9 +93,11 @@ private void openIlastikHDF5() throws IOException
{
final N5HDF5Reader n5 = new N5HDF5Reader( path );

final String dataset = "exported_data";
String dataset = "exported_data";
if ( ! n5.datasetExists( dataset ) )
dataset = "data";

ArrayList< String > axes = getIlastikAxesLabels( n5, dataset );
List< String > axes = fetchAxesLabels( n5, dataset );

final CachedCellImg< T, ? > cachedCellImg = N5Utils.openVolatile( n5, dataset );
channelRAIs = Axes.getChannels( cachedCellImg, axes );
Expand All @@ -115,19 +118,28 @@ private RandomAccessibleInterval< Volatile< T > > getVolatileRAI( CachedCellImg<
}
}

private ArrayList< String > getIlastikAxesLabels( N5HDF5Reader n5, String dataset ) throws IOException
private static List< String > fetchAxesLabels( N5HDF5Reader n5, String dataset ) throws IOException
{
ArrayList< String > axes = new ArrayList<>();
final JsonObject axistags = n5.getAttribute( dataset,"axistags", JsonObject.class );
final JsonArray jsonArray = axistags.get( "axes" ).getAsJsonArray();
for ( JsonElement jsonElement : jsonArray )
try
{
ArrayList< String > axes = new ArrayList<>();
final JsonObject axisTags = n5.getAttribute( dataset, "axistags", JsonObject.class );
final JsonArray jsonArray = axisTags.get( "axes" ).getAsJsonArray();
for ( JsonElement jsonElement : jsonArray )
{
final JsonObject jsonObject = jsonElement.getAsJsonObject();
final String axisLabel = jsonObject.get( "key" ).getAsString();
axes.add( axisLabel );
}
Collections.reverse( axes );
return axes;
}
catch ( Exception e )
{
final JsonObject jsonObject = jsonElement.getAsJsonObject();
final String axisLabel = jsonObject.get( "key" ).getAsString();
axes.add( axisLabel );
List< String > axes = Arrays.asList( "t", "z", "c", "x", "y" );
Collections.reverse( axes );
return axes;
}
Collections.reverse( axes );
return axes;
}

public RandomAccessibleInterval< T > getRAI( int c )
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/develop/OpenIlastikHDF5.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class OpenIlastikHDF5
{
public static void main( String[] args ) throws IOException
{
final CachedCellImgOpener< ? > opener = new CachedCellImgOpener( "/Users/tischer/Desktop/mobie-data/ilastik/A1_2022-07-06-093303-0000--0.4.0-0-1.4.0--tracking-oids.h5", ImageDataFormat.IlastikHDF5, null );
final CachedCellImgOpener< ? > opener = new CachedCellImgOpener( "/Users/tischer/Downloads/export.h5", ImageDataFormat.IlastikHDF5, null );
final RandomAccessibleInterval< ? > rai = opener.getRAI( 0 );
final RandomAccessibleInterval< ? > vRAI = opener.getVolatileRAI( 0 );
}
Expand Down

0 comments on commit 33e5d25

Please sign in to comment.