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();
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations