Module ij
Package ij.process

Class FHT

java.lang.Object
All Implemented Interfaces:
java.lang.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 (../../../../../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 Details

  • 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 <=i < 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 java.lang.String toString()
      Returns a string containing information about this FHT.
      Overrides:
      toString in class ImageProcessor