edu.stanford.rsl.konrad.utils
Class FFTUtil

java.lang.Object
  extended by edu.stanford.rsl.konrad.utils.FFTUtil

public abstract class FFTUtil
extends java.lang.Object

This class is a wrapper for the FFT as implemented in JTransforms.

Author:
Andreas Maier

Constructor Summary
FFTUtil()
           
 
Method Summary
static double abs(int pos, double[] array)
          Computes the absolute value of the complex number at position pos in the array
static double abs(int posx, int posy, double[][] array)
          Computes the absolute values of the complex number at posx, posy in the 2D array array.
static ij.process.ImageProcessor apply2DFilter(ij.process.ImageProcessor imp, ij.process.ImageProcessor filter)
          Applies a 2D filter to the an ImageProcessor
static ij.process.ImageProcessor applyRampFilter_ECC(ij.process.ImageProcessor imp, RampFilter ramp)
          Applies a ramp filter to the an ImageProcessor
static double[] applyRampFilter(double[] detectorRow, RampFilter ramp)
          Applies a ramp filter to the a detector row
static ij.process.ImageProcessor applyRampFilter(ij.process.ImageProcessor imp, RampFilter ramp)
          Applies a ramp filter to the an ImageProcessor
static double[] complexOneOverPiT(int width)
           
static double[] complexSignum(double[] array)
          Computes the complex signum for the given array.
static void copyRampFilter(ij.ImagePlus projections, ij.ImagePlus filteredProjections, double threshold, double percent, boolean meanFilter, boolean showStatus)
           
static double[] cSignum(double[] array)
          Computes the signum for the given complex array.
static double[] discreteHilbertTransfrom(double[] array, int nTimes)
           
static double[] divideAbsolute(double[] one, double[] two)
          Divides two arrays of complex numbers.
static double[] divideComplex(double realOne, double imagOne, double realTwo, double imagTwo)
          Divides two complex values
static ij.process.FloatProcessor estimate2DFilter(ij.ImagePlus filteredProjections, ij.ImagePlus projections, double threshold, boolean showStatus)
          Estimates a 2-D filter given two stacks of projections
static double[] estimateFilter(ij.process.ImageProcessor after, ij.process.ImageProcessor before, double threshold, boolean meanSquare)
          Estimates the applied ramp filter given an input and an output image.
static ij.process.FloatProcessor estimateFilter2D(ij.process.ImageProcessor before, ij.process.ImageProcessor after, double threshold)
          Estimates the applied filter given an input and an output image.
static double[] exactFiniteHilbertTransform(double[] array, int nTimes)
          Exact finite discrete Hilbert transformation after Kak SC.
static double[] fft(double[] array)
           
static double[][] fftshift(double[][] data, boolean bComplex, boolean bSign)
          shift zero frequency to center, or vice verse, 2D.
static double[] fftshift(double[] data, boolean bComplex, boolean bSign)
          shift zero frequency to center, or vice verse, 1D.
static float[][] fftshift(float[][] data, boolean bComplex, boolean bSign)
          shift zero frequency to center, or vice verse, 2D.
static float[] fftshift(float[] data, boolean bComplex, boolean bSign)
          shift zero frequency to center, or vice verse, 1D.
static void GetLowandHighPassImage(float[][] data, float[][] LowPassFilter, float[][] HighPassFilter, float[][] LowPassImage, float[][] HighPassImage)
          Get Lowpass and HighPass Images for "real" image using "real" filters
static int getNextPowerOfTwo(int value)
          Returns the next power of 2 given a certain integer value Code was partially taken from ij.plugin.FFT.java::pad().
static ij.process.ImageProcessor getPowerSpectrum(ij.process.ImageProcessor imp)
          Returns the 2D power spectrum of a given image processor.
static double[] hilbertKernel(int width)
           
static double[] hilbertTransform(double[] array, int nTimes)
          Computes the 1-D Hilbert Transform of the given Array.
static void init1DFFT(int width)
           
static double[] invertRampFilter(double[] filter, double max)
          Estimates an inverse of a Ramp Filter.
static double[] lowPassFilterRealDoubleArray(double[] array, int cutOffIndex)
          low pass filters the given array.
static double[] multiplyAbsolute(double[] one, double[] two)
          Multiplies two arrays of complex numbers.
static double[] multiplyComplex(double[] one, double[] two)
          Multiplies two arrays of complex numbers pairwise
static double[] multiplyComplex(double realOne, double imagOne, double realTwo, double imagTwo)
          Multiplies two complex values
static void printAbsolute(double[] array)
          Prints the absolute values in the given array
static void printComplex(double[] array)
          Prints the complex values in the given array.
static double[] recoverFilter(ij.ImagePlus projections, ij.ImagePlus filteredProjections, double threshold, boolean showStatus)
           
static ij.process.ImageProcessor removeRampFilter(ij.process.ImageProcessor imp, RampFilter ramp, double max)
          Removes a ramp filter from the ImageProcessor.
static void timesComplexNumber(double[] array, double realOne, double imagOne)
          Multiplies the array with the complex number defined as two double values;
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FFTUtil

public FFTUtil()
Method Detail

init1DFFT

public static void init1DFFT(int width)

fft

public static double[] fft(double[] array)

copyRampFilter

public static void copyRampFilter(ij.ImagePlus projections,
                                  ij.ImagePlus filteredProjections,
                                  double threshold,
                                  double percent,
                                  boolean meanFilter,
                                  boolean showStatus)
                           throws java.lang.Exception
Throws:
java.lang.Exception

recoverFilter

public static double[] recoverFilter(ij.ImagePlus projections,
                                     ij.ImagePlus filteredProjections,
                                     double threshold,
                                     boolean showStatus)
                              throws java.lang.Exception
Throws:
java.lang.Exception

complexSignum

public static double[] complexSignum(double[] array)
Computes the complex signum for the given array.

Parameters:
array - the array

cSignum

public static double[] cSignum(double[] array)
Computes the signum for the given complex array.

Parameters:
array - the array

timesComplexNumber

public static void timesComplexNumber(double[] array,
                                      double realOne,
                                      double imagOne)
Multiplies the array with the complex number defined as two double values;

Parameters:
array - the array
realOne - the real part of the complex number
imagOne - the imaginary part of the complex number

complexOneOverPiT

public static double[] complexOneOverPiT(int width)

hilbertKernel

public static double[] hilbertKernel(int width)

hilbertTransform

public static double[] hilbertTransform(double[] array,
                                        int nTimes)
Computes the 1-D Hilbert Transform of the given Array. Uses the Fast Fourier transform to compute the transform

Parameters:
array - the array
nTimes - the size of the zero padding:
            n = 1 zero pad to next power of 2
            n = 2 zero pad to 2 times the next power of 2
Returns:
the Hilbert transformed array

discreteHilbertTransfrom

public static double[] discreteHilbertTransfrom(double[] array,
                                                int nTimes)

exactFiniteHilbertTransform

public static double[] exactFiniteHilbertTransform(double[] array,
                                                   int nTimes)
Exact finite discrete Hilbert transformation after Kak SC. Hilbert Transformation for discrete data. Int J Electronics 34(2):177-83. 1973. Eq. 14

Parameters:
array - the Array
nTimes - Approximation for infinity
Returns:
the array with the Hilbert transform

invertRampFilter

public static double[] invertRampFilter(double[] filter,
                                        double max)
Estimates an inverse of a Ramp Filter. Works in place. The array in the argument list will be changed!

Parameters:
filter - the filter
max - the maximal scaling (1.0 is a good number)
Returns:
the inverted RampFilter

removeRampFilter

public static ij.process.ImageProcessor removeRampFilter(ij.process.ImageProcessor imp,
                                                         RampFilter ramp,
                                                         double max)
Removes a ramp filter from the ImageProcessor. Note that frequencies which were multiplied with 0 cannot be restored. This has to be estimated differently. (If you apply the same filter later on again, it should not matter anyway, as the same frequencies will be multiplied with 0 again.)

Parameters:
imp - the filtered ImageProcessor
ramp - the ramp
max - the maximum for the inverted ramp filter. (try 1.0)
Returns:
the unfiltered ImageProcessor

lowPassFilterRealDoubleArray

public static double[] lowPassFilterRealDoubleArray(double[] array,
                                                    int cutOffIndex)
low pass filters the given array. All indices with a distance greater or equal to cutOffIndex from the highest frequency are set to 0;

Parameters:
array - the real double array
cutOffIndex - the index to start cutting
Returns:
the low pass filtered array.

applyRampFilter_ECC

public static ij.process.ImageProcessor applyRampFilter_ECC(ij.process.ImageProcessor imp,
                                                            RampFilter ramp)
Applies a ramp filter to the an ImageProcessor

Parameters:
imp - the ImageProcessor to be filtered
ramp - the ramp
Returns:
the filtered ImageProcessor

applyRampFilter

public static ij.process.ImageProcessor applyRampFilter(ij.process.ImageProcessor imp,
                                                        RampFilter ramp)
Applies a ramp filter to the an ImageProcessor

Parameters:
imp - the ImageProcessor to be filtered
ramp - the ramp
Returns:
the filtered ImageProcessor

applyRampFilter

public static double[] applyRampFilter(double[] detectorRow,
                                       RampFilter ramp)
Applies a ramp filter to the a detector row

Parameters:
detectorRow - the row
ramp - the ramp
Returns:
the filtered row

apply2DFilter

public static ij.process.ImageProcessor apply2DFilter(ij.process.ImageProcessor imp,
                                                      ij.process.ImageProcessor filter)
Applies a 2D filter to the an ImageProcessor

Parameters:
imp - the ImageProcessor to be filtered
filter - the filter
Returns:
the filtered ImageProcessor

divideComplex

public static double[] divideComplex(double realOne,
                                     double imagOne,
                                     double realTwo,
                                     double imagTwo)
Divides two complex values

Parameters:
realOne - real part one
imagOne - imaginary part one
realTwo - real part two
imagTwo - imaginary part two
Returns:
an array of two values: first entry is real, second imaginary

divideAbsolute

public static double[] divideAbsolute(double[] one,
                                      double[] two)
Divides two arrays of complex numbers. The absolute value of the second array is used to divide the complex first array.

Parameters:
one - the first array
two - the second array
Returns:
the array of null if the lengths of the arrays don't match

multiplyComplex

public static double[] multiplyComplex(double realOne,
                                       double imagOne,
                                       double realTwo,
                                       double imagTwo)
Multiplies two complex values

Parameters:
realOne - real part one
imagOne - imaginary part one
realTwo - real part two
imagTwo - imaginary part two
Returns:
an array of two values: first entry is real, second imaginary

multiplyComplex

public static double[] multiplyComplex(double[] one,
                                       double[] two)
Multiplies two arrays of complex numbers pairwise

Parameters:
one - the first array
two - the second array
Returns:
the array of null if the lengths of the arrays don't match

multiplyAbsolute

public static double[] multiplyAbsolute(double[] one,
                                        double[] two)
Multiplies two arrays of complex numbers. The absolute value of the second array is multiplied to the complex first array.

Parameters:
one - the first array
two - the second array
Returns:
the array of null if the lengths of the arrays don't match

fftshift

public static double[] fftshift(double[] data,
                                boolean bComplex,
                                boolean bSign)
shift zero frequency to center, or vice verse, 1D.

Parameters:
data - the double data to be shifted
bComplex - true: complex; false: real
bSign - true: fftshift; false: ifftshift
Returns:
the fft shifted array

fftshift

public static float[] fftshift(float[] data,
                               boolean bComplex,
                               boolean bSign)
shift zero frequency to center, or vice verse, 1D.

Parameters:
data - the float data to be shifted
bComplex - true: complex; false: real
bSign - true: fftshift; false: ifftshift
Returns:
the fft shifted array

fftshift

public static double[][] fftshift(double[][] data,
                                  boolean bComplex,
                                  boolean bSign)
shift zero frequency to center, or vice verse, 2D.

Parameters:
data - the double data to be shifted
bComplex - true: complex; false: real
bSign - true: fftshift; false: ifftshift
Returns:
the fft shifted array

fftshift

public static float[][] fftshift(float[][] data,
                                 boolean bComplex,
                                 boolean bSign)
shift zero frequency to center, or vice verse, 2D.

Parameters:
data - the double data to be shifted
bComplex - true: complex; false: real
bSign - true: fftshift; false: ifftshift
Returns:
the fft shifted array

GetLowandHighPassImage

public static void GetLowandHighPassImage(float[][] data,
                                          float[][] LowPassFilter,
                                          float[][] HighPassFilter,
                                          float[][] LowPassImage,
                                          float[][] HighPassImage)
Get Lowpass and HighPass Images for "real" image using "real" filters

Parameters:
data - image in real
LowPassFilter - Low pass filter in real
HighPassFilter - High pass filter in real
LowPassImage - Low pass image in real
HighPassImage - High Pass image in real

getPowerSpectrum

public static ij.process.ImageProcessor getPowerSpectrum(ij.process.ImageProcessor imp)
Returns the 2D power spectrum of a given image processor.

Parameters:
imp - the ImageProcessor
Returns:
the power spectrum as ImageProcessor

getNextPowerOfTwo

public static int getNextPowerOfTwo(int value)
Returns the next power of 2 given a certain integer value Code was partially taken from ij.plugin.FFT.java::pad(). Thanks for the inspiration!

Parameters:
value - the input number.
Returns:
the next power of two.

estimate2DFilter

public static ij.process.FloatProcessor estimate2DFilter(ij.ImagePlus filteredProjections,
                                                         ij.ImagePlus projections,
                                                         double threshold,
                                                         boolean showStatus)
                                                  throws java.lang.Exception
Estimates a 2-D filter given two stacks of projections

Parameters:
filteredProjections - the projection data after filtering
projections - the projection data before filtering
threshold - a threshold for outliers (40.0 is not bad)
showStatus - report progress status to ImageJ
Returns:
the filter estimate
Throws:
java.lang.Exception - may happen

estimateFilter2D

public static ij.process.FloatProcessor estimateFilter2D(ij.process.ImageProcessor before,
                                                         ij.process.ImageProcessor after,
                                                         double threshold)
                                                  throws java.lang.Exception
Estimates the applied filter given an input and an output image.

Parameters:
before - the input image
after - the output image
threshold - the maximal value which may appear in the estimate. (to avoid outliers.)
Returns:
the estimate of the applied filter
Throws:
java.lang.Exception - may occur.

estimateFilter

public static double[] estimateFilter(ij.process.ImageProcessor after,
                                      ij.process.ImageProcessor before,
                                      double threshold,
                                      boolean meanSquare)
                               throws java.lang.Exception
Estimates the applied ramp filter given an input and an output image.

Parameters:
after - the output image
before - the input image
Returns:
the estimate of the applied filter
Throws:
java.lang.Exception - may occur.

abs

public static double abs(int pos,
                         double[] array)
Computes the absolute value of the complex number at position pos in the array

Parameters:
pos - the position
array - the array which contains the values
Returns:
the absolute value

abs

public static double abs(int posx,
                         int posy,
                         double[][] array)
Computes the absolute values of the complex number at posx, posy in the 2D array array.

Parameters:
posx - x position
posy - y position
array - the array
Returns:
the absolute value of the complex number

printAbsolute

public static void printAbsolute(double[] array)
Prints the absolute values in the given array

Parameters:
array - the array of complex values

printComplex

public static void printComplex(double[] array)
Prints the complex values in the given array.

Parameters:
array - the array