Skip to content

Commit

Permalink
streamline code a bit, make computeSigma method public
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Mar 18, 2024
1 parent 7df4439 commit 38e9a03
Showing 1 changed file with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + ", " +
Expand Down Expand Up @@ -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<FloatType, FloatType, FloatType>()
{
@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;
Expand Down Expand Up @@ -320,6 +301,28 @@ else if ( localization == 1 )
return finalPeaks;
}

public static Pair<double[][], Float > 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<SimplePeak> findPeaks( final RandomAccessibleInterval< FloatType > laPlace, final RandomAccessibleInterval< FloatType > laPlaceMask, final float minValue, final ExecutorService service )
{
final Interval interval = Intervals.expand( laPlace, -1 );
Expand Down

0 comments on commit 38e9a03

Please sign in to comment.