From 38e9a03987e93d5dbb97674bda139b45310852e0 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Mon, 18 Mar 2024 10:36:12 -0400 Subject: [PATCH] streamline code a bit, make computeSigma method public --- .../methods/dog/DoGImgLib2.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/preibisch/mvrecon/process/interestpointdetection/methods/dog/DoGImgLib2.java b/src/main/java/net/preibisch/mvrecon/process/interestpointdetection/methods/dog/DoGImgLib2.java index e89174af..0e190d6a 100644 --- a/src/main/java/net/preibisch/mvrecon/process/interestpointdetection/methods/dog/DoGImgLib2.java +++ b/src/main/java/net/preibisch/mvrecon/process/interestpointdetection/methods/dog/DoGImgLib2.java @@ -60,7 +60,9 @@ import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Intervals; +import net.imglib2.util.Pair; import net.imglib2.util.Util; +import net.imglib2.util.ValuePair; import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.legacy.registration.bead.laplace.LaPlaceFunctions; @@ -207,24 +209,11 @@ public static < T extends RealType< T > > ArrayList< InterestPoint > computeDoG( // normalize image final RandomAccessible< FloatType > inputFloat = ImgLib2Tools.normalizeVirtual( input, min, max ); - final float k = LaPlaceFunctions.computeK( 4 ); - final float K_MIN1_INV = LaPlaceFunctions.computeKWeight(k); - final int steps = 3; - - // - // Compute the Sigmas for the gaussian convolution - // - final double[] sigma1 = new double[ input.numDimensions() ]; - final double[] sigma2 = new double[ input.numDimensions() ]; - - for ( int d = 0; d < input.numDimensions(); ++d ) - { - final float[] sigmaStepsX = LaPlaceFunctions.computeSigma( steps, k, initialSigma ); - final float[] sigmaStepsDiffX = LaPlaceFunctions.computeSigmaDiff( sigmaStepsX, 0.5f ); - - sigma1[ d ] = sigmaStepsDiffX[0]; - sigma2[ d ] = sigmaStepsDiffX[1]; - } + // compute sigmas + final Pair< double[][], Float > sigmas = computeSigmas( initialSigma, inputFloat.numDimensions() ); + final double[] sigma1 = sigmas.getA()[ 0 ]; + final double[] sigma2 = sigmas.getA()[ 1 ]; + final float K_MIN1_INV = sigmas.getB(); if ( !silent ) IOFunctions.println( "(" + new Date(System.currentTimeMillis()) + "): computing DoG with (sigma=" + initialSigma + ", " + @@ -260,15 +249,7 @@ public static < T extends RealType< T > > ArrayList< InterestPoint > computeDoG( gauss2 = LazyWeightedGauss.init( inputFloat, maskFloat, interval, new FloatType(), sigma2, blockSize ); } - final RandomAccessibleInterval< FloatType > dog = Converters.convert(gauss2, gauss1, new BiConverter() - { - @Override - public void convert( final FloatType inputA, final FloatType inputB, final FloatType output) - { - output.setReal( ( inputA.getRealDouble() - inputB.getRealDouble() ) * K_MIN1_INV ); - } - }, new FloatType() ); - + final RandomAccessibleInterval< FloatType > dog = Converters.convert(gauss2, gauss1, (iA,iB,o) -> o.setReal( ( iA.getRealDouble() - iB.getRealDouble() ) * K_MIN1_INV ), new FloatType() ); // no caching since it is a simple subtraction operation, the underlying Gauss is expensive final RandomAccessibleInterval< FloatType > dogCached = dog; @@ -320,6 +301,28 @@ else if ( localization == 1 ) return finalPeaks; } + public static Pair computeSigmas( final float initialSigma, final int n ) + { + final float k = LaPlaceFunctions.computeK( 4 ); + final float K_MIN1_INV = LaPlaceFunctions.computeKWeight(k); + final int steps = 3; + + // + // Compute the Sigmas for the gaussian convolution + // + final double[][] sigma = new double[2][ n ]; + + for ( int d = 0; d < n; ++d ) + { + final float[] sigmaStepsX = LaPlaceFunctions.computeSigma( steps, k, initialSigma ); + final float[] sigmaStepsDiffX = LaPlaceFunctions.computeSigmaDiff( sigmaStepsX, 0.5f ); + + sigma[0][ d ] = sigmaStepsDiffX[0]; + sigma[1][ d ] = sigmaStepsDiffX[1]; + } + + return new ValuePair<>( sigma, K_MIN1_INV ); + } public static ArrayList findPeaks( final RandomAccessibleInterval< FloatType > laPlace, final RandomAccessibleInterval< FloatType > laPlaceMask, final float minValue, final ExecutorService service ) { final Interval interval = Intervals.expand( laPlace, -1 );