L_FFTBitmap

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_FFTBitmap(pBitmap, pFTArray, uFlags)

Computes the Fast Fourier transform of an image or the Inverse Fast Fourier transform as specified in the uFlags.

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle that references the bitmap, object of the transformation.

pFTARRAY pFTArray

Pointer to FTARRAY structure. The acxData member of the FTARRAY structure is a two-dimensional array that will hold the frequency components of the image. Its size must be the same as the image. The function will fill the array elements using data from pBitmap when FFT_FFT flag is passed. The function will use the array values and reconstruct pBitmap when FFT_IFFT flag is passed.

L_UINT uFlags

Flags that indicate the transformation type, operation channel, frequency data type used to reconstruct the image, and the clipping type. You can use a bit-wise OR (|) to specify one flag from each group.

The following flags represent the transformation type:

Value Meaning
FFT_FFT [0x0001] Convert the image into frequency domain and store the results in the acxData.
FFT_IFFT [0x0002] Construct an image from the frequency components in acxData. The image will be stored in pBitmap. This option will change the values of acxData.

The following flags represent the operation channel type:

Value Meaning
FFT_BLUE [0x0010] Work on the blue channel.
FFT_GREEN [0x0020] Work on the green channel.
FFT_RED [0x0030] Work on the red channel.
FFT_GRAY [0x0040] Work on the master Channel. If this flag is combined with FFT_IFFT, the reconstructed image will be gray.

The following flags represent the frequency data type used for constructing the image: this flag is used only if FFT_IFFT is set and will be ignored if FT_FFT is set:

Value Meaning
FFT_IFFT_MAG [0x0100] Construct the image from the frequency magnitude only.
FFT_IFFT_PHS [0x0200] Construct the image from the frequency phase only.
FFT_IFFT_BOTH [0x0300] Construct the image from both magnitude and phase.

The following flags represent the clipping type. This flag is used only if FFT_IFFT is set and will be ignored if FFT_FFT is set:

Value Meaning
FFT_IFFT_CLIP [0x1000] Clip the constructed image values to be between 0 and 255.
FFT_IFFT_SCL [0x2000] Scale the constructed image Valid values are between 0 and 255.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function converts the image from the time domain to the frequency domain and vice versa using a Fast Fourier Transform algorithm. Fast Fourier Transform algorithms are a simplification of a Discrete Fourier Transform and require that the image dimensions must be power of two (i.e. 2, 4, 8, 16, 32etc). The number of computations needed are reduced from 2N2 to 2N LgN. Use the L_DFTBitmap to use a Discrete Fourier Transform algorithm on a bitmap. If you try to use this function with a bitmap with dimensions that are not a power of two, the function will return an ERROR_INV_PARAMETER error.

When using this function with an image where at least one of its dimensions aren't a power of two, you must specify an extra flag when calling the L_AllocFTArray function to pad the dimension(s) to the nearest power of two. If you try to use this function with a bitmap with dimensions that are not a power of two without specifying a "padding" flag, the function will return an ERROR_INV_PARAMETER error.

Before using this function, call the L_AllocFTArray function to allocate a FTARRAY structure large enough to hold the Fourier Transform coefficients for pBitmap. When the array is no longer needed, free the allocated array by calling the L_FreeFTArray function.

This function does not work on regions. If a bitmap has a region the function ignores it and processes the entire bitmap.

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function does not support 12 and 16-bit grayscale and 48 and 64-bit color images. If the image is 12 and 16-bit grayscale and 48 and 64-bit color, the function will not return an error.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example loads a bitmap and applies a FFT transformation.

L_INT FFTBitmapExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
   pFTARRAY  pFTArray; 
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\FourierTransform.jpg")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* Resize the bitmap to make sure the bitmap dimensions are power of two*/ 
   nRet = L_SizeBitmap(&LeadBitmap, 256, 512, SIZE_BICUBIC); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* Allocate FFT buffer*/ 
   nRet = L_AllocFTArray(&LeadBitmap, &pFTArray, sizeof(FTARRAY), 0); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* Apply FFT*/ 
   nRet = L_FFTBitmap(&LeadBitmap, pFTArray, FFT_FFT | FFT_GRAY); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* Free FFT buffer */ 
   nRet = L_FreeFTArray(pFTArray, 0); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   //free bitmap  
   if(LeadBitmap.Flags.Allocated)   
      L_FreeBitmap(&LeadBitmap);   
   return SUCCESS; 
} 

Help Version 21.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.