use of org.jtransforms.fft.DoubleFFT_2D 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;
}
Aggregations