Skip to content

Commit

Permalink
Speed-up DOWN_AVERAGE downsampling for NativeType
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Sep 24, 2024
1 parent 649fb88 commit ae1fd67
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1282,13 +1287,27 @@ private static <T extends NumericType<T>> RandomAccessibleInterval<T> 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<T> imgE = Views.interpolate(Views.extendBorder(img), new NLinearInterpolatorFactory());
return Views.interval(RealViews.transform(imgE, new ScaleAndTranslation(scale, translation)),
new FinalInterval(dims));
}

private static <T extends NativeType<T>> RandomAccessibleInterval<T> downsampleAvgBy2NativeType(
final RandomAccessibleInterval<T> img, final int[] downsampleFactors, final long[] dimensions) {

final int[] cellDimensions = new int[] {32};
final BlockSupplier<T> 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);
Expand Down

0 comments on commit ae1fd67

Please sign in to comment.