From ae1fd673df53c97dc2de0d8dd1585cdf54067f89 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 24 Sep 2024 12:33:19 +0200 Subject: [PATCH] Speed-up DOWN_AVERAGE downsampling for NativeType --- .../n5/ij/N5ScalePyramidExporter.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/ij/N5ScalePyramidExporter.java b/src/main/java/org/janelia/saalfeldlab/n5/ij/N5ScalePyramidExporter.java index 51b8e780..f62380b2 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/ij/N5ScalePyramidExporter.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/ij/N5ScalePyramidExporter.java @@ -57,6 +57,11 @@ import javax.swing.JTextPane; import javax.swing.UIManager; +import net.imglib2.algorithm.blocks.BlockAlgoUtils; +import net.imglib2.algorithm.blocks.BlockSupplier; +import net.imglib2.algorithm.blocks.downsample.Downsample; +import net.imglib2.util.Util; +import net.imglib2.view.fluent.RandomAccessibleIntervalView.Extension; import org.janelia.saalfeldlab.n5.Compression; import org.janelia.saalfeldlab.n5.DatasetAttributes; import org.janelia.saalfeldlab.n5.GzipCompression; @@ -1282,6 +1287,10 @@ private static > RandomAccessibleInterval downsample } } + if (img.getType() instanceof NativeType) { + return downsampleAvgBy2NativeType((RandomAccessibleInterval) img, Util.long2int(downsampleFactors), dims); + } + // TODO clamping NLinearInterpFactory when relevant // TODO record offset in metadata as (s-0.5) final RealRandomAccessible imgE = Views.interpolate(Views.extendBorder(img), new NLinearInterpolatorFactory()); @@ -1289,6 +1298,16 @@ private static > RandomAccessibleInterval downsample new FinalInterval(dims)); } + private static > RandomAccessibleInterval downsampleAvgBy2NativeType( + final RandomAccessibleInterval img, final int[] downsampleFactors, final long[] dimensions) { + + final int[] cellDimensions = new int[] {32}; + final BlockSupplier blocks = BlockSupplier + .of(img.view().extend(Extension.border())) + .andThen(Downsample.downsample(downsampleFactors)); + return BlockAlgoUtils.cellImg(blocks, dimensions, cellDimensions); + } + private int[] sliceBlockSize(final int exclude) { return removeElement(chunkSize, exclude);