/** Returns a clone of this FHT. */ public FHT getCopy() { ImageProcessor ip = super.duplicate(); FHT fht = new FHT(ip); fht.isFrequencyDomain = isFrequencyDomain; fht.quadrantSwapNeeded = quadrantSwapNeeded; fht.rgb = rgb; fht.originalWidth = originalWidth; fht.originalHeight = originalHeight; fht.originalBitDepth = originalBitDepth; fht.originalColorModel = originalColorModel; return fht; }
/** Returns a clone of this FHT. */ public FHT getCopy() { ImageProcessor ip = super.duplicate(); FHT fht = new FHT(ip); fht.isFrequencyDomain = isFrequencyDomain; fht.quadrantSwapNeeded = quadrantSwapNeeded; fht.rgb = rgb; fht.originalWidth = originalWidth; fht.originalHeight = originalHeight; fht.originalBitDepth = originalBitDepth; fht.originalColorModel = originalColorModel; return fht; }
private static FHT createPaddedFFTImage(FloatProcessor nextImage, int paddedSize) { FHT imageFFT = new FHT(Padding.PADDING_ZERO.padToBiggerSquare(nextImage, paddedSize)); imageFFT.setShowProgress(false); imageFFT.transform(); return imageFFT; }
FHT newFHT(ImageProcessor ip) { FHT fht; int width = ip.getWidth(); int height = ip.getHeight(); int maxN = Math.max(width, height); int size = 2; while (size<1.5*maxN) size *= 2; rect.x = (int)Math.round((size-width)/2.0); rect.y = (int)Math.round((size-height)/2.0); rect.width = width; rect.height = height; FFTFilter fftFilter = new FFTFilter(); if (ip instanceof ColorProcessor) { showStatus("Extracting brightness"); ImageProcessor ip2 = ((ColorProcessor)ip).getBrightness(); fht = new FHT(fftFilter.tileMirror(ip2, size, size, rect.x, rect.y)); fht.rgb = (ColorProcessor)ip.duplicate(); // save so we can later update the brightness } else fht = new FHT(fftFilter.tileMirror(ip, size, size, rect.x, rect.y)); fht.originalWidth = originalWidth; fht.originalHeight = originalHeight; fht.originalBitDepth = imp.getBitDepth(); return fht; }
/** Complex to Complex Inverse Fourier Transform * Author: Joachim Wesner */ void c2c2DFFT(float[] rein, float[] imin, int maxN, float[] reout, float[] imout) { FHT fht = new FHT(new FloatProcessor(maxN,maxN)); float[] fhtpixels = (float[])fht.getPixels(); // Real part of inverse transform for (int iy = 0; iy < maxN; iy++) cplxFHT(iy, maxN, rein, imin, false, fhtpixels); fht.inverseTransform(); // Save intermediate result, so we can do a "in-place" transform float[] hlp = new float[maxN*maxN]; System.arraycopy(fhtpixels, 0, hlp, 0, maxN*maxN); // Imaginary part of inverse transform for (int iy = 0; iy < maxN; iy++) cplxFHT(iy, maxN, rein, imin, true, fhtpixels); fht.inverseTransform(); System.arraycopy(hlp, 0, reout, 0, maxN*maxN); System.arraycopy(fhtpixels, 0, imout, 0, maxN*maxN); }
FHT newFHT(ImageProcessor ip) { FHT fht; if (ip instanceof ColorProcessor) { showStatus("Extracting brightness"); ImageProcessor ip2 = ((ColorProcessor)ip).getBrightness(); fht = new FHT(pad(ip2)); fht.rgb = (ColorProcessor)ip.duplicate(); // save so we can later update the brightness } else fht = new FHT(pad(ip)); if (padded) { fht.originalWidth = originalWidth; fht.originalHeight = originalHeight; } int bitDepth = imp.getBitDepth(); fht.originalBitDepth = bitDepth; if (bitDepth!=24) fht.originalColorModel = ip.getColorModel(); return fht; }
FHT newFHT(ImageProcessor ip) { FHT fht; int width = ip.getWidth(); int height = ip.getHeight(); int maxN = Math.max(width, height); int size = 2; while (size<1.5*maxN) size *= 2; rect.x = (int)Math.round((size-width)/2.0); rect.y = (int)Math.round((size-height)/2.0); rect.width = width; rect.height = height; FFTFilter fftFilter = new FFTFilter(); if (ip instanceof ColorProcessor) { showStatus("Extracting brightness"); ImageProcessor ip2 = ((ColorProcessor)ip).getBrightness(); fht = new FHT(fftFilter.tileMirror(ip2, size, size, rect.x, rect.y)); fht.rgb = (ColorProcessor)ip.duplicate(); // save so we can later update the brightness } else fht = new FHT(fftFilter.tileMirror(ip, size, size, rect.x, rect.y)); fht.originalWidth = originalWidth; fht.originalHeight = originalHeight; fht.originalBitDepth = imp.getBitDepth(); return fht; }
FHT newFHT(ImageProcessor ip) { FHT fht; if (ip instanceof ColorProcessor) { showStatus("Extracting brightness"); ImageProcessor ip2 = ((ColorProcessor)ip).getBrightness(); fht = new FHT(pad(ip2)); fht.rgb = (ColorProcessor)ip.duplicate(); // save so we can later update the brightness } else fht = new FHT(pad(ip)); if (padded) { fht.originalWidth = originalWidth; fht.originalHeight = originalHeight; } int bitDepth = imp.getBitDepth(); fht.originalBitDepth = bitDepth; if (bitDepth!=24) fht.originalColorModel = ip.getColorModel(); return fht; }
/** Complex to Complex Inverse Fourier Transform * Author: Joachim Wesner */ void c2c2DFFT(float[] rein, float[] imin, int maxN, float[] reout, float[] imout) { FHT fht = new FHT(new FloatProcessor(maxN,maxN)); float[] fhtpixels = (float[])fht.getPixels(); // Real part of inverse transform for (int iy = 0; iy < maxN; iy++) cplxFHT(iy, maxN, rein, imin, false, fhtpixels); fht.inverseTransform(); // Save intermediate result, so we can do a "in-place" transform float[] hlp = new float[maxN*maxN]; System.arraycopy(fhtpixels, 0, hlp, 0, maxN*maxN); // Imaginary part of inverse transform for (int iy = 0; iy < maxN; iy++) cplxFHT(iy, maxN, rein, imin, true, fhtpixels); fht.inverseTransform(); System.arraycopy(hlp, 0, reout, 0, maxN*maxN); System.arraycopy(fhtpixels, 0, imout, 0, maxN*maxN); }
void swapQuadrants(ImageStack stack) { FHT fht = new FHT(new FloatProcessor(1, 1)); for (int i=1; i<=stack.getSize(); i++) fht.swapQuadrants(stack.getProcessor(i)); }
void swapQuadrants(ImageStack stack) { FHT fht = new FHT(new FloatProcessor(1, 1)); for (int i=1; i<=stack.getSize(); i++) fht.swapQuadrants(stack.getProcessor(i)); }
Variable[] fourierArray() { interp.getLeftParen(); Variable[] a = getArray(); int windowType = FHT.NO_WINDOW; if (interp.nextToken()==',') { interp.getComma(); String windowS = getString().toLowerCase(); if (windowS.equals("hamming")) windowType = FHT.HAMMING; else if (windowS.startsWith("hann")) //sometimes also called 'Hanning' windowType = FHT.HANN; else if (windowS.startsWith("flat")) windowType = FHT.FLATTOP; else if (!windowS.startsWith("no")) interp.error("Invalid Fourier window '"+windowType+"'"); } interp.getRightParen(); int n = a.length; float[] data = new float[n]; for (int i=0; i<n; i++) data[i] = (float)a[i].getValue(); float[] result = new FHT().fourier1D(data, windowType); int n2 = result.length; Variable[] a2 = new Variable[n2]; for (int i=0; i<n2; i++) a2[i] = new Variable(result[i]); return a2; }
FHT multiply(FHT fht, boolean conjugate) { int rowMod, cMod, colMod; double h2e, h2o; float[] h1 = (float[])getPixels(); float[] h2 = (float[])fht.getPixels(); float[] tmp = new float[maxN*maxN]; for (int r =0; r<maxN; r++) { rowMod = (maxN - r) % maxN; for (int c=0; c<maxN; c++) { colMod = (maxN - c) % maxN; h2e = (h2[r * maxN + c] + h2[rowMod * maxN + colMod]) / 2; h2o = (h2[r * maxN + c] - h2[rowMod * maxN + colMod]) / 2; if (conjugate) tmp[r * maxN + c] = (float)(h1[r * maxN + c] * h2e - h1[rowMod * maxN + colMod] * h2o); else tmp[r * maxN + c] = (float)(h1[r * maxN + c] * h2e + h1[rowMod * maxN + colMod] * h2o); } } FHT fht2 = new FHT(new FloatProcessor(maxN, maxN, tmp, null)); fht2.isFrequencyDomain = true; return fht2; }
FHT multiply(FHT fht, boolean conjugate) { int rowMod, cMod, colMod; double h2e, h2o; float[] h1 = (float[])getPixels(); float[] h2 = (float[])fht.getPixels(); float[] tmp = new float[maxN*maxN]; for (int r =0; r<maxN; r++) { rowMod = (maxN - r) % maxN; for (int c=0; c<maxN; c++) { colMod = (maxN - c) % maxN; h2e = (h2[r * maxN + c] + h2[rowMod * maxN + colMod]) / 2; h2o = (h2[r * maxN + c] - h2[rowMod * maxN + colMod]) / 2; if (conjugate) tmp[r * maxN + c] = (float)(h1[r * maxN + c] * h2e - h1[rowMod * maxN + colMod] * h2o); else tmp[r * maxN + c] = (float)(h1[r * maxN + c] * h2e + h1[rowMod * maxN + colMod] * h2o); } } FHT fht2 = new FHT(new FloatProcessor(maxN, maxN, tmp, null)); fht2.isFrequencyDomain = true; return fht2; }
void doFHTInverseTransform() { FHT fht = new FHT(imp.getProcessor().duplicate()); fht.inverseTransform(); fht.resetMinAndMax(); String name = WindowManager.getUniqueName(imp.getTitle().substring(7)); new ImagePlus(name, fht).show(); }
void doFHTInverseTransform() { FHT fht = new FHT(imp.getProcessor().duplicate()); fht.inverseTransform(); fht.resetMinAndMax(); String name = WindowManager.getUniqueName(imp.getTitle().substring(7)); new ImagePlus(name, fht).show(); }
/** Returns the image resulting from the point by point Hartley division of this image by the specified image. Both images are assumed to be in the frequency domain. Division in the frequency domain is equivalent to deconvolution in the space domain. */ public FHT divide(FHT fht) { int rowMod, cMod, colMod; double mag, h2e, h2o; float[] h1 = (float[])getPixels(); float[] h2 = (float[])fht.getPixels(); float[] out = new float[maxN*maxN]; for (int r=0; r<maxN; r++) { rowMod = (maxN - r) % maxN; for (int c=0; c<maxN; c++) { colMod = (maxN - c) % maxN; mag =h2[r*maxN+c] * h2[r*maxN+c] + h2[rowMod*maxN+colMod] * h2[rowMod*maxN+colMod]; if (mag<1e-20) mag = 1e-20; h2e = (h2[r*maxN+c] + h2[rowMod*maxN+colMod]); h2o = (h2[r*maxN+c] - h2[rowMod*maxN+colMod]); double tmp = (h1[r*maxN+c] * h2e - h1[rowMod*maxN+colMod] * h2o); out[r*maxN+c] = (float)(tmp/mag); } } FHT fht2 = new FHT(new FloatProcessor(maxN, maxN, out, null)); fht2.isFrequencyDomain = true; return fht2; }
/** * Convert an image into a Fourier image with real and imaginary parts * * @param ip - image * @return the real and imaginary parts */ public FloatProcessor[] getComplexFFT(ImageProcessor ip) { FloatProcessor taperedDataImage = getSquareTaperedImage(ip); FHT fht = new FHT(taperedDataImage); fht.setShowProgress( false ); fht.transform(); FloatProcessor[] ret = new FloatProcessor[2]; ImageStack stack1 = fht.getComplexTransform(); ret[0] = ((FloatProcessor) stack1.getProcessor(1)); ret[1] = ((FloatProcessor) stack1.getProcessor(2)); return ret; }
private ImagePlus openFFT(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); FHT fht = new FHT(ip, true); ImageProcessor ps = fht.getPowerSpectrum(); ImagePlus imp2 = new ImagePlus(imp.getTitle(), ps); imp2.setProperty("FHT", fht); imp2.setProperty("Info", imp.getInfoProperty()); fht.originalWidth = (int)imp2.getNumericProperty("width"); fht.originalHeight = (int)imp2.getNumericProperty("height"); fht.originalBitDepth = (int)imp2.getNumericProperty("bitdepth"); fht.originalColorModel = ip.getColorModel(); imp2.setCalibration(imp.getCalibration()); return imp2; }
private ImagePlus openFFT(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); FHT fht = new FHT(ip, true); ImageProcessor ps = fht.getPowerSpectrum(); ImagePlus imp2 = new ImagePlus(imp.getTitle(), ps); imp2.setProperty("FHT", fht); imp2.setProperty("Info", imp.getInfoProperty()); fht.originalWidth = (int)imp2.getNumericProperty("width"); fht.originalHeight = (int)imp2.getNumericProperty("height"); fht.originalBitDepth = (int)imp2.getNumericProperty("bitdepth"); fht.originalColorModel = ip.getColorModel(); imp2.setCalibration(imp.getCalibration()); return imp2; }