Skip navigation

This Question is Assumed Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
1,229 Views 1 Reply Last post: Nov 27, 2009 7:54 AM by AndreasL RSS
ALitz Member 2 posts since
Oct 16, 2009
Currently Being Moderated

Nov 17, 2009 3:17 PM

rfft2d_fr16 and ifft2d_fr16 problem

Hi,

 

Im attempting to do an FFT/IFFT on an 8-bit image, but am having poor results with the following code, which simply attempts to do an FFT, then an inverse, to make sure that not too much precision has been lost.   I guess I am uncertain whether or not I am scaling the data correctly?  I am using VDSP 5.0, update 6.

 

The resultant image I get out of the IFFT vaguely resembles the input image, but with much precision lost....

 

Original Image:

----------------------

 

InputImage.bmp

 

Output Image after IFFT:

-------------------------------------

 

IIFFT.bmp

 

 

// Calculate Twiddle

complex_fract16* t_t = (complex_fract16*)malloc(sizeof(complex_fract16)*64);
twidfft2d_fr16(t_t,64);

 

  fract16* pDst=  pInputMatrix;
  unsigned char* pSrc = pI1;

// I am attempting to convert 8-bit image data

// to [1 -1], then convert to fract 16 data type?

  for(int ii = 0; ii < 64*64 ; ii++)
  {
    // Scale to 1 to -1
    float fVal = (*pSrc++);
    fVal = (fVal-128)/255;
    fract16 frac =  float_to_fr16(fVal);
    *pDst++ = frac;
  }       

 

// Do the FFT

rfft2d_fr16(pInputMatrix,pTempMatrix, pOutputMatrix, t_t, 1, 64, 0, 0);
// Immediately do the inverse, to see what I end up with
ifft2d_fr16(pOutputMatrix, pTempMatrix, pFinalMatrix, t_t, 1, 64, 0, 0);

...

// Convert back to 8-bit?

for(int ii = 0; ii < 64*64 ; ii++)
{
      float fVal =  fr16_to_float(pSrc->re);
      fVal = (fVal*255)+128;
      *pDst = (unsigned char)fVal;
       pSrc++; pDst++; 
  }

Attachments:
AndreasL Analog Employee 18 posts since
May 26, 2009
Currently Being Moderated
1. Nov 27, 2009 7:54 AM in response to: Alex Litz
Re: rfft2d_fr16 and ifft2d_fr16 problem

Please find attached an example for an alternative rfft2d implementation.

 

The function will first convert your unsigned 8-bit data to signed fract16 data. How the conversion is performed can be controlled by setting the macros EXPOSURE_ADJUST (image brightness) and RESOLUTION_ADJUST (the dynamic range available). The values can be positive or negative, providing further means to control the appearance of the converted image.

 

After conversion, the function will compute the FFT for each row using static scaling (dividing the signal by 64) which will minimize round-off errors. Before computing the FFTs for each column, the magnitude of the data is increased. Without this step the subsequent static scaling would have resulted in most output values being close to zero. This way more image information is retained.

 

The corresponding ifft could be designed along the same lines: FFT for each row, increasing the magnitude, FFT for each column and lastly the conversion back to 8-bits.

Attachments:

More Like This

  • Retrieving data ...

Bookmarked By (0)