Search in sources :

Example 6 with Fht

use of uk.ac.sussex.gdsc.core.ij.process.Fht in project GDSC-SMLM by aherbert.

the class FhtFilter method initialiseKernel.

/**
 * Initialise the kernel FHT. It is recreated only if the target size has changed.
 *
 * @param maxx the width of the target image
 * @param maxy the height of the target image
 */
public void initialiseKernel(int maxx, int maxy) {
    final int maxN = MathUtils.nextPow2(MathUtils.max(maxx, maxy, kn));
    final int size = maxN * maxN;
    if (tmp == null || tmp.length != size) {
        tmp = new float[size];
    }
    if (kernelFht != null && maxN == kernelFht.getWidth()) {
        // Already initialised
        return;
    }
    // No window function for the kernel so just create a new FHT
    float[] data;
    if (kw < maxN || kh < maxN) {
        // Too small so insert in the middle
        data = new float[size];
        final int x = getInsert(maxN, kw);
        final int y = getInsert(maxN, kh);
        insert(kernel, kw, data, maxN, x, y);
    } else {
        // Clone to avoid destroying data
        data = kernel.clone();
    }
    // Do the transform using JTransforms as it is faster. Do not allow multi-threading.
    final long begin = CommonUtils.getThreadsBeginN_2D();
    CommonUtils.setThreadsBeginN_2D(Long.MAX_VALUE);
    dht = new FloatDHT_2D(maxN, maxN);
    CommonUtils.setThreadsBeginN_2D(begin);
    dht.forward(data);
    kernelFht = new Fht(data, maxN, true);
    if (operation == Operation.DECONVOLUTION) {
        kernelFht.initialiseFastOperations();
    } else {
        kernelFht.initialiseFastMultiply();
    }
}
Also used : FloatDHT_2D(org.jtransforms.dht.FloatDHT_2D) Fht(uk.ac.sussex.gdsc.core.ij.process.Fht)

Example 7 with Fht

use of uk.ac.sussex.gdsc.core.ij.process.Fht in project GDSC-SMLM by aherbert.

the class PcPalmAnalysis method computeAutoCorrelationFht.

/**
 * Compute auto correlation FHT.
 *
 * @param fftIm in frequency domain
 * @return the auto correlation FHT.
 */
private static FloatProcessor computeAutoCorrelationFht(Fht fftIm) {
    final Fht fht2 = fftIm.conjugateMultiply(fftIm);
    fht2.inverseTransform();
    fht2.swapQuadrants();
    return fht2;
}
Also used : Fht(uk.ac.sussex.gdsc.core.ij.process.Fht)

Example 8 with Fht

use of uk.ac.sussex.gdsc.core.ij.process.Fht in project GDSC-SMLM by aherbert.

the class PcPalmAnalysis method padToFht2.

/**
 * Pads the image to the next power of two and transforms into the frequency domain.
 *
 * @param ip the image
 * @return An FHT2 image in the frequency domain
 */
private static Fht padToFht2(ImageProcessor ip) {
    final FloatProcessor im2 = pad(ip);
    if (im2 == null) {
        return null;
    }
    final Fht fht2 = new Fht(im2);
    fht2.transform();
    return fht2;
}
Also used : Fht(uk.ac.sussex.gdsc.core.ij.process.Fht) FloatProcessor(ij.process.FloatProcessor)

Example 9 with Fht

use of uk.ac.sussex.gdsc.core.ij.process.Fht in project GDSC-SMLM by aherbert.

the class PcPalmAnalysis method computeAutoCorrelationCurveFht.

/**
 * Compute the auto-correlation curve using FHT (ImageJ built-in). Computes the correlation image
 * and then samples the image at radii up to the specified length to get the average correlation
 * at a given radius.
 *
 * @param im the image
 * @param wp the weighted image
 * @param maxRadius the max radius
 * @param nmPerPixel the nm per pixel
 * @param density the density
 * @return { distances[], gr[], gr_se[] }
 */
@Nullable
private double[][] computeAutoCorrelationCurveFht(ImageProcessor im, ImageProcessor wp, int maxRadius, double nmPerPixel, double density) {
    log("Creating Hartley transforms");
    final Fht fht2Im = padToFht2(im);
    final Fht fht2W = padToFht2(wp);
    if (fht2Im == null || fht2W == null) {
        error("Unable to perform Hartley transform");
        return null;
    }
    log("Performing correlation");
    final FloatProcessor corrIm = computeAutoCorrelationFht(fht2Im);
    final FloatProcessor corrW = computeAutoCorrelationFht(fht2W);
    IJ.showProgress(1);
    final int centre = corrIm.getHeight() / 2;
    final Rectangle crop = new Rectangle(centre - maxRadius, centre - maxRadius, maxRadius * 2, maxRadius * 2);
    if (settings.showCorrelationImages) {
        displayCorrelation(corrIm, "Image correlation", crop);
        displayCorrelation(corrW, "Window correlation", crop);
    }
    log("Normalising correlation");
    final FloatProcessor correlation = normaliseCorrelation(corrIm, corrW, density);
    if (settings.showCorrelationImages) {
        displayCorrelation(correlation, "Normalised correlation", crop);
    }
    return computeRadialAverage(maxRadius, nmPerPixel, correlation);
}
Also used : Fht(uk.ac.sussex.gdsc.core.ij.process.Fht) FloatProcessor(ij.process.FloatProcessor) Rectangle(java.awt.Rectangle) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable)

Example 10 with Fht

use of uk.ac.sussex.gdsc.core.ij.process.Fht in project GDSC-SMLM by aherbert.

the class JTransformsTest method canComputeFhtUsingJTransforms.

@Test
void canComputeFhtUsingJTransforms() {
    // Note: no need to test the correlation as the transformed data
    // is the same format as FHT so we just test that.
    final int size = 16;
    final int ex = 5;
    final int ey = 7;
    final int ox = 1;
    final int oy = 2;
    final FloatProcessor fp1 = createProcessor(size, ex, ey, 4, 4, null);
    final FloatProcessor fp2 = createProcessor(size, size / 2 + ox, size / 2 + oy, 4, 4, null);
    final float[] input1 = (float[]) fp1.getPixels();
    final float[] input2 = (float[]) fp2.getPixels();
    final Fht fht1 = new Fht(input1.clone(), size, false);
    final Fht fht2 = new Fht(input2.clone(), size, false);
    fht1.transform();
    fht2.transform();
    // Do the same with JTransforms
    final FloatDHT_2D dht = new FloatDHT_2D(size, size);
    dht.forward(input1);
    dht.forward(input2);
    Assertions.assertArrayEquals(fht1.getData(), input1, 1e-5f);
    Assertions.assertArrayEquals(fht2.getData(), input2, 1e-5f);
}
Also used : FloatDHT_2D(org.jtransforms.dht.FloatDHT_2D) Fht(uk.ac.sussex.gdsc.core.ij.process.Fht) FloatProcessor(ij.process.FloatProcessor) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Aggregations

Fht (uk.ac.sussex.gdsc.core.ij.process.Fht)12 FloatProcessor (ij.process.FloatProcessor)7 Test (org.junit.jupiter.api.Test)3 FloatDHT_2D (org.jtransforms.dht.FloatDHT_2D)2 Nullable (uk.ac.sussex.gdsc.core.annotation.Nullable)2 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)2 ImageProcessor (ij.process.ImageProcessor)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 LinkedList (java.util.LinkedList)1 Future (java.util.concurrent.Future)1 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)1 FloatFFT_2D (org.jtransforms.fft.FloatFFT_2D)1 AlignImagesFft (uk.ac.sussex.gdsc.core.ij.AlignImagesFft)1 NullTrackProgress (uk.ac.sussex.gdsc.core.logging.NullTrackProgress)1 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)1 TrackProgress (uk.ac.sussex.gdsc.core.logging.TrackProgress)1 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)1 TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)1 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)1