From 7dee12fd02953b8ed4a5a95ac11971d2edcedb76 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Mon, 9 Sep 2024 11:00:10 +0200 Subject: [PATCH 1/3] Simplify N5ResaveTools.writeS0Block --- .../mvrecon/process/resave/N5ResaveTools.java | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java b/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java index c74f8f1b..9443bc0e 100644 --- a/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java +++ b/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java @@ -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; @@ -237,45 +239,27 @@ public static void createS0Datasets( } } - public static void writeS0Block( + public static > void writeS0Block( final SpimData2 data, final N5Writer n5, final long[][] gridBlock ) { final ViewId viewId = new ViewId( (int)gridBlock[ 3 ][ 0 ], (int)gridBlock[ 3 ][ 1 ]); - 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 = "setup" + viewId.getViewSetupId() + "/timepoint" + viewId.getTimePointId() + "/s0"; - if ( dataType == DataType.UINT16 ) - { - @SuppressWarnings("unchecked") - final RandomAccessibleInterval 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 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 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] ) ); } From 8ba4407d4b579d3a54c593892c9c3b2c8e20141d Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Mon, 9 Sep 2024 11:59:50 +0200 Subject: [PATCH 2/3] Bugfix: absolut and relative scale arguments were flipped --- .../net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java index 999be978..4f8e540b 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java @@ -190,7 +190,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 allBlocks = - N5ResaveTools.prepareDownsampling( vidsToResave, n5Writer, level, downsamplings[ s ], ds, blockSize, compression ); + N5ResaveTools.prepareDownsampling( vidsToResave, n5Writer, level, ds, downsamplings[ s ], blockSize, compression ); time = System.currentTimeMillis(); From 0ba6e36c3d838568a700775d9b32e1dfba168706 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Mon, 9 Sep 2024 12:00:04 +0200 Subject: [PATCH 3/3] bugfix --- .../net/preibisch/mvrecon/process/resave/N5ResaveTools.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java b/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java index 9443bc0e..ca510720 100644 --- a/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java +++ b/src/main/java/net/preibisch/mvrecon/process/resave/N5ResaveTools.java @@ -185,7 +185,7 @@ public static ArrayList prepareDownsampling( }); // set additional N5 attributes for sN dataset - n5.setAttribute(dataset, "downsamplingFactors", absoluteDownsampling[ level ] ); + n5.setAttribute(dataset, "downsamplingFactors", absoluteDownsampling); } return allBlocks;