Module ij
Package ij.process

# Class FHT

java.lang.Object
ij.process.ImageProcessor
ij.process.FloatProcessor
ij.process.FHT

All Implemented Interfaces:
  `Cloneable`

public class FHT extends FloatProcessor
This class contains a Java implementation of the Fast Hartley Transform. It is based on Pascal code in NIH Image contributed by Arlo Reeves (http://imagej.nih.gov/ij/docs/ImageFFT/). The Fast Hartley Transform was restricted by U.S. Patent No. 4,646,256, but was placed in the public domain by Stanford University in 1995 and is now freely available.

## Field Summary

Fields
Modifier and Type
Field
Description
`static int`
`FLATTOP`
`static int`
`HAMMING`
`static int`
`HANN`
`static int`
`NO_WINDOW`
`int`
`originalBitDepth`
Used by the FFT class.
`ColorModel`
`originalColorModel`
Used by the FFT class.
`int`
`originalHeight`
Used by the FFT class.
`int`
`originalWidth`
Used by the FFT class.
`double`
`powerSpectrumMean`
Used by the FFT class.
`boolean`
`quadrantSwapNeeded`
Used by the FFT class.
`ColorProcessor`
`rgb`
Used by the FFT class.

### Fields inherited from class ij.process.FloatProcessor

`pixels8`

### Fields inherited from class ij.process.ImageProcessor

`antialiasedText, baseCM, BICUBIC, BILINEAR, BLACK, BLACK_AND_WHITE_LUT, BLUR_MORE, bLUT1, bLUT2, boldFont, CENTER_JUSTIFY, clipXMax, clipXMin, clipYMax, clipYMin, cm, cm2, CONVOLVE, cTable, cx, cy, defaultColorModel, drawingColor, fillValueSet, FIND_EDGES, fmGraphics, fmImage, font, fontMetrics, gLUT1, gLUT2, height, histogramMax, histogramMin, histogramSize, image, img, interpolate, interpolationMethod, inversionTested, INVERT_PROJECTION, invertedLut, ISODATA, ISODATA2, justification, LEFT_JUSTIFY, lineWidth, lutAnimation, lutUpdateMode, MAX, MAX_PROJECTION, maxThreshold, MEDIAN_FILTER, MIN, MIN_PROJECTION, minMaxSet, minThreshold, NEAREST_NEIGHBOR, newPixels, NO_LUT_UPDATE, NO_THRESHOLD, NONE, OVER_UNDER_LUT, raster, RED_LUT, RIGHT_JUSTIFY, rLUT1, rLUT2, rnd, roiHeight, roiWidth, roiX, roiY, sampleModel, seed, SET_FIRST_CHANNEL, snapshotHeight, snapshotWidth, source, SUM_PROJECTION, UPDATE_BLUE, UPDATE_GREEN, UPDATE_RED, width, xMax, xMin, yMax, yMin`

## Constructor Summary

Constructors
Constructor
Description
`FHT()`
`FHT(ImageProcessor ip)`
Constructs a FHT object from an ImageProcessor.
`FHT(ImageProcessor ip, boolean isFrequencyDomain)`

## Method Summary

Modifier and Type
Method
Description
`FHT`
`conjugateMultiply(FHT fht)`
Returns the image resulting from the point by point Hartley conjugate multiplication of this image and the specified image.
`void`
`dfht3(float[] x, int base, boolean inverse, int maxN)`
Performs an optimized 1D FHT of an array or part of an array.
`FHT`
`divide(FHT fht)`
Returns the image resulting from the point by point Hartley division of this image by the specified image.
`float[]`
`fourier1D(float[] data, int windowType)`
Calculates the Fourier amplitudes of an array, based on a 1D Fast Hartley Transform.
`ImageStack`
`getComplexTransform()`
Converts this FHT to a complex Fourier transform and returns it as a two slice stack.
`FHT`
`getCopy()`
Returns a clone of this FHT.
`ImageProcessor`
`getPowerSpectrum()`
Returns an 8-bit power spectrum, log-scaled to 1-254.
`FloatProcessor`
`getRawPowerSpectrum()`
Returns the unscaled 32-bit power spectrum.
`void`
`inverseTransform()`
Performs an inverse transform, converting this image into the space domain.
`void`
`inverseTransform1D(float[] fht)`
Performs an inverse 1D Fast Hartley Transform (FHT) of an array
`static boolean`
`isPowerOf2(int n)`
`FHT`
`multiply(FHT fht)`
Returns the image resulting from the point by point Hartley multiplication of this image and the specified image.
`boolean`
`powerOf2Size()`
Returns true of this FHT contains a square image with a width that is a power of two.
`void`
`rc2DFHT(float[] x, boolean inverse, int maxN)`
Performs a 2D FHT (Fast Hartley Transform).
`void`
`setShowProgress(boolean showProgress)`
Enables/disables display of the progress bar during transforms.
`void`
`swapQuadrants()`
Swap quadrants 1 and 3 and 2 and 4 of the image contained in this FHT.
`void`
`swapQuadrants(ImageProcessor ip)`
Swap quadrants 1 and 3 and 2 and 4 of the specified ImageProcessor so the power spectrum origin is at the center of the image.
`String`
`toString()`
Returns a string containing information about this FHT.
`void`
`transform()`
Performs a forward transform, converting this image into the frequency domain.
`void`
`transform1D(float[] x)`
Performs an optimized 1D Fast Hartley Transform (FHT) of an array.

### Methods inherited from class ij.process.FloatProcessor

`abs, add, add, and, applyTable, autoThreshold, convolve, convolve3x3, copyBits, createImage, createMask, createProcessor, crop, dilate, drawPixel, duplicate, erode, exp, fill, fill, filter, findMinAndMax, flipVertical, gamma, get, get, getBackgroundValue, getBicubicInterpolatedPixel, getBitDepth, getBufferedImage, getf, getf, getForegroundValue, getHistogram, getInterpolatedPixel, getMax, getMin, getPixel, getPixel, getPixelInterpolated, getPixels, getPixelsCopy, getPixelValue, getSnapshotPixels, invert, log, max, maxValue, medianFilter, min, minValue, multiply, noise, or, putPixel, putPixel, putPixelValue, reset, reset, resetMinAndMax, resize, rotate, scale, set, set, set, setBackgroundColor, setBackgroundValue, setColor, setf, setf, setLutAnimation, setMinAndMax, setPixels, setPixels, setSnapshotPixels, setThreshold, setValue, snapshot, sqr, sqrt, swapPixelArrays, threshold, toFloat, xor`

### Methods inherited from class ij.process.ImageProcessor

`applyMacro, bin, blurGaussian, clone, convertToByte, convertToByteProcessor, convertToByteProcessor, convertToColorProcessor, convertToFloat, convertToFloatProcessor, convertToRGB, convertToShort, convertToShortProcessor, convertToShortProcessor, cubic, draw, drawDot, drawDot2, drawLine, drawLine4, drawOval, drawOverlay, drawPolygon, drawRect, drawRoi, drawString, drawString, drawString, fill, fillOutside, fillOval, fillPolygon, fillRect, fillValueSet, findEdges, flipHorizontal, getAutoThreshold, getAutoThreshold, getBestIndex, getCalibrationTable, getColorModel, getColumn, getColumn, getCurrentColorModel, getDefaultColorModel, getFloatArray, getFont, getFontMetrics, getHeight, getHistogram, getHistogramMax, getHistogramMin, getHistogramSize, getIndexSampleModel, getIntArray, getInterpolate, getInterpolatedValue, getInterpolationMethod, getInterpolationMethods, getLine, getLineWidth, getLut, getLutUpdateMode, getMask, getMaskArray, getMaxThreshold, getMinThreshold, getNChannels, getNeighborhood, getOverlay, getPixelCount, getProgressIncrement, getRoi, getRow, getRow, getSliceNumber, getStatistics, getStats, getStringBounds, getStringWidth, getThresholdColorModel, getValue, getWidth, hideProgress, insert, invertLut, isBinary, isColorLut, isDefaultLut, isGrayscale, isInvertedLut, isKillable, isPseudoColorLut, isSigned16Bit, isThreshold, lineTo, ln, makeDefaultColorModel, maskSizeError, moveTo, putColumn, putColumn, putRow, putRow, resetBinaryThreshold, resetRoi, resetThreshold, resize, resize, resizeLinearly, rotateLeft, rotateRight, scaleAndSetThreshold, setAntialiasedText, setAutoThreshold, setAutoThreshold, setAutoThreshold, setAutoThreshold, setAutoThreshold, setBinaryThreshold, setCalibrationTable, setClipRect, setColor, setColor, setColor, setColorModel, setFloatArray, setFont, setFontSize, setGlobalBackgroundColor, setGlobalForegroundColor, setHistogramRange, setHistogramSize, setIntArray, setInterpolate, setInterpolationMethod, setJustification, setLineWidth, setLut, setMask, setOverColor, setOverlay, setProgressBar, setRandomSeed, setRoi, setRoi, setRoi, setRoi, setSliceNumber, setSnapshotCopyMode, setThreshold, setUnderColor, setUseBicubic, sharpen, showProgress, smooth, subtract, threshold, translate, translate, updateComposite`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### quadrantSwapNeeded

public boolean quadrantSwapNeeded
Used by the FFT class.

### rgb

public ColorProcessor rgb
Used by the FFT class.

### originalWidth

public int originalWidth
Used by the FFT class.

### originalHeight

public int originalHeight
Used by the FFT class.

### originalBitDepth

public int originalBitDepth
Used by the FFT class.

### originalColorModel

public ColorModel originalColorModel
Used by the FFT class.

### powerSpectrumMean

public double powerSpectrumMean
Used by the FFT class.

### NO_WINDOW

public static int NO_WINDOW

### HAMMING

public static int HAMMING

### HANN

public static int HANN

### FLATTOP

public static int FLATTOP

## Constructor Details

### FHT

public FHT(ImageProcessor ip)
Constructs a FHT object from an ImageProcessor. Byte, short and RGB images are converted to float. Float images are duplicated.

### FHT

public FHT(ImageProcessor ip, boolean isFrequencyDomain)

### FHT

public FHT()

## Method Details

### powerOf2Size

public boolean powerOf2Size()
Returns true of this FHT contains a square image with a width that is a power of two.

### transform

public void transform()
Performs a forward transform, converting this image into the frequency domain. The image contained in this FHT must be square and its width must be a power of 2.

### inverseTransform

public void inverseTransform()
Performs an inverse transform, converting this image into the space domain. The image contained in this FHT must be square and its width must be a power of 2.

### fourier1D

public float[] fourier1D(float[] data, int windowType)
Calculates the Fourier amplitudes of an array, based on a 1D Fast Hartley Transform. With no Window function, if the array size is a power of 2, the input function should be either periodic or the data at the beginning and end of the array should approach the same value (the periodic continuation should be smooth). With no Window function, if the array size is not a power of 2, the data should decay towards 0 at the beginning and end of the array. For data that do not fulfill these conditions, a window function can be used to avoid artifacts from the edges. See http://en.wikipedia.org/wiki/Window_function. Supported window functions: Hamming, Hann ("raised cosine"), flat-top. Flat-top refers to the HFT70 function in the report cited below, it is named for its response in the frequency domain: a single-frequency sinewave becomes a peak with a short plateau of 3 roughly equal Fourier amplitudes. It is optimized for measuring amplitudes of signals with well-separated sharp frequencies. All window functions will reduce the frequency resolution; this is especially pronounced for the flat-top window. Normalization is done such that the peak height in the Fourier transform (roughly) corresponds to the RMS amplitude of a sinewave (i.e., amplitude/sqrt(2)), and the first Fourier amplitude corresponds to DC component (average value of the data). If the sine frequency falls between two discrete frequencies of the Fourier transform, peak heights can deviate from the true RMS amplitude by up to approx. 36, 18, 15, and 0.1% for no window function, Hamming, Hann and flat-top window functions, respectively. When calculating the power spectrum from the square of the output, note that the result is quantitative only if the input array size is a power of 2; then the spectral density of the power spectrum must be divided by 1.3628 for the Hamming, 1.5 for the Hann, and 3.4129 for the flat-top window. For more details about window functions, see: G. Heinzel, A. Rdiger, and R. Schilling Spectrum and spectral density estimation by the discrete Fourier transform (DFT), including a comprehensive list of window functions and some new flat-top windows. Technical Report, MPI f. Gravitationsphysik, Hannover, 2002; http://edoc.mpg.de/395068

Parameters:
  `data` - Input array; its size need not be a power of 2. The input is not modified..
  `windowType` - may be NO_WINDOW, then the input array is used as it is. Otherwise, it is multiplied by a window function, which can be HAMMING, HANN or FLATTOP.
Returns:
  Array with the result, i.e., the RMS amplitudes for each frequency. The output array size is half the size of the 2^n-sized array used for the FHT; array element [0]corresponds to frequency zero (the "DC component"). The first nonexisting array element, result[result.length] would correspond to a frequency of 1 cycle per 2 input points, i.e., the Nyquist frequency. In other words, if the spacing of the input data points is dx, results[i] corresponds to a frequency of i/(2*results.length*dx).

### transform1D

public void transform1D(float[] x)
Performs an optimized 1D Fast Hartley Transform (FHT) of an array. Array size must be a power of 2. Note that all amplitudes in the output 'x' are multiplied by the array length. Therefore, to get the power spectrum, for 1 invalid input: '<'=i invalid input: '<' N/2, use ps[i] = (x[i]*x[i]+x[maxN-i]*x[maxN-i])/(maxN*maxN), where maxN is the array length. To get the real part of the complex FFT, for i=0 use x[0]/maxN, and for i>0, use (x[i]+x[maxN-i])/(2*maxN). The imaginary part of the complex FFT, with i>0, is given by (x[i]-x[maxN-i])/(2*maxN) The coefficients of cosine and sine are like the real and imaginary values above, but you have to divide by maxN instead of 2*maxN.

### inverseTransform1D

public void inverseTransform1D(float[] fht)
Performs an inverse 1D Fast Hartley Transform (FHT) of an array

### rc2DFHT

public void rc2DFHT(float[] x, boolean inverse, int maxN)
Performs a 2D FHT (Fast Hartley Transform).

### dfht3

public void dfht3(float[] x, int base, boolean inverse, int maxN)
Performs an optimized 1D FHT of an array or part of an array.

Parameters:
  `x` - Input array; will be overwritten by the output in the range given by base and maxN.
  `base` - First index from where data of the input array should be read.
  `inverse` - True for inverse transform.
  `maxN` - Length of data that should be transformed; this must be always the same for a given FHT object. Note that all amplitudes in the output 'x' are multiplied by maxN.

### getPowerSpectrum

public ImageProcessor getPowerSpectrum()
Returns an 8-bit power spectrum, log-scaled to 1-254. The image in this FHT is assumed to be in the frequency domain.

### getRawPowerSpectrum

public FloatProcessor getRawPowerSpectrum()
Returns the unscaled 32-bit power spectrum.

### getComplexTransform

public ImageStack getComplexTransform()
Converts this FHT to a complex Fourier transform and returns it as a two slice stack. Author: Joachim Wesner

### swapQuadrants

public void swapQuadrants(ImageProcessor ip)
Swap quadrants 1 and 3 and 2 and 4 of the specified ImageProcessor so the power spectrum origin is at the center of the image.

                        2 1
                        3 4

### swapQuadrants

public void swapQuadrants()
Swap quadrants 1 and 3 and 2 and 4 of the image contained in this FHT.

### multiply

public FHT multiply(FHT fht)
Returns the image resulting from the point by point Hartley multiplication of this image and the specified image. Both images are assumed to be in the frequency domain. Multiplication in the frequency domain is equivalent to convolution in the space domain.

### conjugateMultiply

public FHT conjugateMultiply(FHT fht)
Returns the image resulting from the point by point Hartley conjugate multiplication of this image and the specified image. Both images are assumed to be in the frequency domain. Conjugate multiplication in the frequency domain is equivalent to correlation in the space domain.

### divide

public FHT divide(FHT fht)
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.

### setShowProgress

public void setShowProgress(boolean showProgress)
Enables/disables display of the progress bar during transforms.

### getCopy

public FHT getCopy()
Returns a clone of this FHT.

### isPowerOf2

public static boolean isPowerOf2(int n)

### toString

public String toString()
Returns a string containing information about this FHT.

Overrides:
  `toString` in class `ImageProcessor`