Skip to content

Commit

Permalink
Merge branch 'master' of github.com:PreibischLab/multiview-reconstruc…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
StephanPreibisch committed Sep 9, 2024
2 parents d65b1df + 0ba6e36 commit 878cc19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ else if ( URITools.isS3( n5Params.n5URI ) || URITools.isGC( n5Params.n5URI ) )*/
IOFunctions.println( "Downsampling: " + Util.printCoordinates( downsamplings[ s ] ) + " with relative downsampling of " + Util.printCoordinates( ds ));

final ArrayList<long[][]> allBlocks =
N5ResaveTools.prepareDownsampling( vidsToResave, n5Writer, level, downsamplings[ s ], ds, blockSize, compression );
N5ResaveTools.prepareDownsampling( vidsToResave, n5Writer, level, ds, downsamplings[ s ], blockSize, compression );

time = System.currentTimeMillis();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import mpicbg.spim.data.sequence.ViewSetup;
import net.imglib2.FinalInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Cast;
import net.imglib2.util.Util;
import net.imglib2.view.Views;
import net.preibisch.legacy.io.IOFunctions;
Expand Down Expand Up @@ -200,7 +202,7 @@ public static ArrayList<long[][]> prepareDownsampling(
});

// set additional N5 attributes for sN dataset
n5.setAttribute(dataset, "downsamplingFactors", absoluteDownsampling[ level ] );
n5.setAttribute(dataset, "downsamplingFactors", absoluteDownsampling);
}

return allBlocks;
Expand Down Expand Up @@ -254,47 +256,27 @@ public static void createS0Datasets(
}
}

public static void resaveS0Block(
public static <T extends NativeType<T>> void resaveS0Block(
final SpimData2 data,
final N5Writer n5,
final DataType dataType,
final Function<long[][], String> gridBlockToDataset, // gridBlock to dataset name for s0
final long[][] gridBlock )
{
final ViewId viewId = new ViewId( (int)gridBlock[ 3 ][ 0 ], (int)gridBlock[ 3 ][ 1 ]);
final String dataset = gridBlockToDataset.apply( gridBlock );

final SetupImgLoader< ? > imgLoader = data.getSequenceDescription().getImgLoader().getSetupImgLoader( viewId.getViewSetupId() );

@SuppressWarnings("rawtypes")
final RandomAccessibleInterval img = imgLoader.getImage( viewId.getTimePointId() );

//final DataType dataType = n5.getAttribute( "setup" + viewId.getViewSetupId(), "dataType", DataType.class );
final String dataset = gridBlockToDataset.apply( gridBlock );// "setup" + viewId.getViewSetupId() + "/timepoint" + viewId.getTimePointId() + "/s0";

if ( dataType == DataType.UINT16 )
{
@SuppressWarnings("unchecked")
final RandomAccessibleInterval<UnsignedShortType> sourceGridBlock = Views.offsetInterval(img, gridBlock[0], gridBlock[1]);
N5Utils.saveNonEmptyBlock(sourceGridBlock, n5, dataset, gridBlock[2], new UnsignedShortType());
}
else if ( dataType == DataType.UINT8 )
{
@SuppressWarnings("unchecked")
final RandomAccessibleInterval<UnsignedByteType> sourceGridBlock = Views.offsetInterval(img, gridBlock[0], gridBlock[1]);
N5Utils.saveNonEmptyBlock(sourceGridBlock, n5, dataset, gridBlock[2], new UnsignedByteType());
}
else if ( dataType == DataType.FLOAT32 )
{
@SuppressWarnings("unchecked")
final RandomAccessibleInterval<FloatType> sourceGridBlock = Views.offsetInterval(img, gridBlock[0], gridBlock[1]);
N5Utils.saveNonEmptyBlock(sourceGridBlock, n5, dataset, gridBlock[2], new FloatType());
}
else
if ( dataType != DataType.UINT16 && dataType != DataType.UINT8 && dataType != DataType.FLOAT32 )
{
n5.close();
throw new RuntimeException("Unsupported pixel type: " + dataType );
}

final SetupImgLoader< ? > imgLoader = data.getSequenceDescription().getImgLoader().getSetupImgLoader( viewId.getViewSetupId() );
final RandomAccessibleInterval< T > img = Cast.unchecked( imgLoader.getImage( viewId.getTimePointId() ) );
final RandomAccessibleInterval< T > sourceGridBlock = Views.offsetInterval( img, gridBlock[ 0 ], gridBlock[ 1 ] );
N5Utils.saveNonEmptyBlock( sourceGridBlock, n5, dataset, gridBlock[ 2 ], img.getType().createVariable() );

System.out.println( "ViewId " + Group.pvid( viewId ) + ", written block: offset=" + Util.printCoordinates( gridBlock[0] ) + ", dimension=" + Util.printCoordinates( gridBlock[1] ) );
}

Expand Down

0 comments on commit 878cc19

Please sign in to comment.