Search in sources :

Example 6 with FHT2

use of ij.process.FHT2 in project GDSC-SMLM by aherbert.

the class PCPALMAnalysis method computeAutoCorrelationFFT.

/**
	 * Compute the auto-correlation using the JTransforms FFT library
	 * 
	 * @param ip
	 * @return
	 */
private FloatProcessor computeAutoCorrelationFFT(ImageProcessor ip) {
    FloatProcessor paddedIp = pad(ip);
    if (paddedIp == null)
        return null;
    final int size = paddedIp.getWidth();
    boolean doubleFFT = false;
    float[] pixels = (float[]) paddedIp.getPixels();
    float[] correlation = new float[size * size];
    if (doubleFFT) {
        DoubleFFT_2D fft = new DoubleFFT_2D(size, size);
        double[] data = new double[size * size * 2];
        for (int i = 0; i < pixels.length; i++) data[i] = pixels[i];
        fft.realForwardFull(data);
        // Re-use data
        for (int i = 0, j = 0; i < data.length; i += 2, j++) {
            data[j] = data[i] * data[i] + data[i + 1] * data[i + 1];
        }
        // Zero fill
        for (int j = correlation.length; j < data.length; j++) data[j] = 0;
        // Re-use the pre-computed object
        //fft = new DoubleFFT_2D(size, size);
        fft.realInverseFull(data, true);
        // Get the real part of the data
        for (int i = 0, j = 0; i < data.length; i += 2, j++) {
            correlation[j] = (float) data[i];
        }
    } else {
        FloatFFT_2D fft = new FloatFFT_2D(size, size);
        float[] data = new float[size * size * 2];
        System.arraycopy(pixels, 0, data, 0, pixels.length);
        fft.realForwardFull(data);
        // Re-use data
        for (int i = 0, j = 0; i < data.length; i += 2, j++) {
            data[j] = data[i] * data[i] + data[i + 1] * data[i + 1];
        }
        // Zero fill
        for (int j = correlation.length; j < data.length; j++) data[j] = 0;
        // Re-use the pre-computed object
        //fft = new FloatFFT_2D(size, size);
        fft.realInverseFull(data, true);
        // Get the real part of the data
        for (int i = 0, j = 0; i < data.length; i += 2, j++) {
            correlation[j] = data[i];
        }
    }
    // Swap quadrants
    FloatProcessor fp = new FloatProcessor(size, size, correlation, null);
    new FHT2().swapQuadrants(fp);
    return fp;
}
Also used : FHT2(ij.process.FHT2) FloatFFT_2D(org.jtransforms.fft.FloatFFT_2D) FloatProcessor(ij.process.FloatProcessor) DoubleFFT_2D(org.jtransforms.fft.DoubleFFT_2D)

Aggregations

FHT2 (ij.process.FHT2)6 FloatProcessor (ij.process.FloatProcessor)5 FloatFFT_2D (org.jtransforms.fft.FloatFFT_2D)2 NullTrackProgress (gdsc.core.logging.NullTrackProgress)1 TrackProgress (gdsc.core.logging.TrackProgress)1 ImageStack (ij.ImageStack)1 Rectangle (java.awt.Rectangle)1 DoubleFFT_2D (org.jtransforms.fft.DoubleFFT_2D)1