Core Optical, Inc.
FourierTransform ComputeForwardTransform Method Industrial Strength, Scientific Grade
Performs a forward FFT of the specified channel in the SourceData object.

Namespace: PrecisionImage.FrequencyDomainProcessing
Assembly: PrecisionImage (in PrecisionImage.dll) Version: 2.0.0.0 (2.0.0.0)
Syntax

public FourierSpectrum ComputeForwardTransform(
	SourceData sourceData,
	int sourceChannel,
	WindowFunction windowFunction = null,
	Int32Rect regionOfInterest = null
)

Parameters

sourceData
Type: PrecisionImage SourceData
A SourceData type representing the spatial domain image data.
sourceChannel
Type: OnlineSystem Int32
An OnlineInt32 type indicating the channel from which the spectrum is to be computed.
windowFunction (Optional)
Type: PrecisionImage.WindowFunctions WindowFunction
A WindowFunction encapsulating the type of apodization window to be applied to the data. Default is no window.
regionOfInterest (Optional)
Type: OnlineSystem.Windows Int32Rect
An OnlineInt32Rect type specifying the region of the data to transform. Default is the entire data image.

Return Value

A FourierSpectrum type containing the computed spectrum of the input channel.
Exceptions

Remarks

Performs a forward FFT of the data contained in the specified sourceChannel of sourceData using its current PaddingMode and ProcessingMode properties and (optionally) pre-applying the specified WindowFunction to the data. This method accepts non-integer powers of 2 SourceData channels, which are automatically zero-padded according to the PaddingMode property. If no channel is specified, processing is performed on the first channel (channel = 0). Processing is not performed in-place i.e. the data contained in the SourceData channel is not altered. The result is returned as a FourierSpectrum object encapsulating the complex result in DC-centered format. The dimensions of the output data may differ from the input data if zero-padding is required to force the rows and/or columns to integer powers of 2. The output values are scaled according to the inverse square-root of the product of the number of zero-padded rows and columns.

Examples

The following performs a forward and inverse FFT using quadratic zero padding (the default). In addtion, it zeros-out an arbitrary region of low frequencies.
using PrecisionImage;
using PrecisionImage.FrequencyDomainProcessing;

// Create the BitmapSource object: 
Uri imageUri              = new Uri("Coral.tif", UriKind.Relative);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource sourceImage  = decoder.Frames[0];

// Display original image:
image0.Source = sourceImage;

// Instantiate the SourceData object and load image data using default sRGB gamma encoding: 
SourceData imageData = new SourceData(sourceImage);

// Instantiate the FFT transform object: 
FourierTransform fft = new FourierTransform();

// Perform a forward FFT on the image data: 
Int32 ChannelOfInterest  = 0;
FourierSpectrum spectrum = fft.ComputeForwardTransform(imageData, ChannelOfInterest);

// Eliminate an arbitrary portion of the low frequencies. This should normally be done 
// more effectively and efficiently by using one of the IsotropicFrequencyFilter objects, but  
// is performed manually here simply to illustrate the use of the FourierTransform and FourierSpectrum  
// classes in PrecisionImage.NET: 
Int32 FilterDimension = spectrum.FrequencyDomainColumns / 12;
Int32 FilterStart     = (spectrum.FrequencyDomainColumns / 2) - (FilterDimension / 2);
Int32 FilterStop      = FilterStart + FilterDimension;

// Apply ideal high-pass zonal filter: 
for (Int32 row = FilterStart; row < FilterStop; row++)
{
    for(Int32 column = FilterStart; column < FilterStop; column++)
    {
        spectrum.SetRealAndImaginaryComponents(row, column, 0.0f, 0.0f);
    }
}

// Perform inverse FFT on this altered spectrum, inserting the result back into the first channel:
fft.ComputeInverseTransform(spectrum, imageData);

// Display channel using an Image component, scaled as gamma-encoded 8-bit grayscale: 
image1.Source = imageData.GetChannelImage(PixelFormats.Gray8, GammaEncoding.sRGB, ChannelOfInterest);

// Finally, increase the contrast of the high frequency image details by forcing the 
// values to scale linearly within a smaller range by using the OutputWindowing overload version of 
// "GetChannelImage": 

// Get the current min/max data values in the high-frequency image: 
OutputWindowing originalScale = imageData.GetDefaultDataWindows();

// Compute a truncated range within which the output image is to be scaled: 
Single OriginalMin = originalScale.GetWindowMinClip(0);
Single OriginalMax = originalScale.GetWindowMaxClip(0);
Single DataSpan    = OriginalMax - OriginalMin;
Single NewMin      = OriginalMin + (DataSpan / 4.0f);

// Generate the newly scaled high-frequency image and assign it to an Image component:
image2.Source = imageData.GetChannelImage(PixelFormats.Gray8, GammaEncoding.sRGB, 0, new OutputWindowing(NewMin, OriginalMax, ChannelOfInterest));

The above example generates 3 images similar to the following:

The following example illustrates the use of the window functions when applied to a forward FFT operation. This example generates a series of spectra based upon a synthetic sinewave image and weighted by various weighting window types to illustrate the different window effects on spectral-leakage reduction.

using PrecisionImage;
using PrecisionImage.FrequencyDomainProcessing;
using PrecisionImage.WindowFunctions;

// Create the BitmapSource object: 
Uri imageUri             = new Uri("RotatedSine.bmp", UriKind.Relative);
BmpBitmapDecoder decoder = new BmpBitmapDecoder(imageUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource sourceImage = decoder.Frames[0];

// Instantiate the two SourceData objects and load image data using default sRGB gamma encoding: 
SourceData imageData1 = new SourceData(sourceImage);
SourceData imageData2 = new SourceData(sourceImage);

//Instantiate the Fourier Transform object: 
FourierTransform fft = new FourierTransform();

// Instantiate the Hanning window: 
HanningWindowFunction hanningFunction = new HanningWindowFunction();

// Perform forward FFT on the first channel using squared Hanning window 
// and display: 
FourierSpectrum spectrum = fft.ComputeForwardTransform(imageData1, 0, hanningFunction);
image3.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Switch window to elliptical style:
hanningFunction.Style = FunctionStyle.Elliptical;

// Generate the spectrum again and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, hanningFunction);
image4.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Change the window type to a squared Kaiser with Beta = 3.0: 
KaiserWindowFunction kaiserFunction = new KaiserWindowFunction(3.0);

// Perform forward FFT on the first channel using squared Kaiser window 
// and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, kaiserFunction);
image5.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Switch window to elliptical style:
kaiserFunction.Style = FunctionStyle.Elliptical;

// Generate the spectrum again and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, kaiserFunction);
image6.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Alter tuning Beta and Style for the Kaiser window:
kaiserFunction.Beta  = 6.5;
kaiserFunction.Style = FunctionStyle.Squared;

// Perform forward FFT on the first channel using squared Kaiser window 
// and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, kaiserFunction);
image7.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Switch window to elliptical style:
kaiserFunction.Style = FunctionStyle.Elliptical;

// Generate the spectrum again and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, kaiserFunction);
image8.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Alter tuning Beta and Style for the Kaiser window again:
kaiserFunction.Beta  = 9.0;
kaiserFunction.Style = FunctionStyle.Squared;

// Perform forward FFT on the first channel using squared Kaiser window 
// and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, kaiserFunction);
image9.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Switch window to elliptical style:
kaiserFunction.Style = FunctionStyle.Elliptical;

// Generate the spectrum again and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, kaiserFunction);
image10.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Repeat process with a Parzen window: 
ParzenWindowFunction parzenFunction = new ParzenWindowFunction();

// Perform forward FFT on the first channel using squared Parzen window 
// and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, parzenFunction);
image11.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Switch window to elliptical style:
parzenFunction.Style = FunctionStyle.Elliptical;

// Generate the spectrum again and display:
spectrum      = fft.ComputeForwardTransform(imageData1, 0, parzenFunction);
image12.Source = spectrum.GetPowerSpectrumImage(PixelFormats.Gray8);

// Finally, apply a Hanning window to the data directly and display (for 
// the purpose of visualizing the window styles). Use sRGB gamma encoding 
// for the output image to better visualize the window extents:
hanningFunction.Style = FunctionStyle.Squared;
hanningFunction.ApplyWindow(imageData1, 0);
image1.Source = imageData1.GetChannelImage(PixelFormats.Gray8, GammEncoding.sRGB, 0);

// Repeat process with elliptical window:
hanningFunction.Style = FunctionStyle.Elliptical;
hanningFunction.ApplyWindow(imageData2, 0);
image2.Source = imageData2.GetChannelImage(PixelFormats.Gray8, GammaEncoding.sRGB, 0);

The above example generates a series of figures similar to the following:

See Also