Im using the following code to generate the visualization of fourier transform using FFTW and OpenCV. However, I’m only getting the upper part of the image correctly.
Can anyone explain if there is something wrong with the code?
fft stores the fftw_execute data.
int nl= fftvis->height; // number of lines
// total number of element per line
int nc= fftvis->width * fftvis->nChannels;
// get the pointer to the image buffer
unsigned char *data= reinterpret_cast<unsigned char *>
(fftvis->imageData);
k =0;
for (int x=1; x<nl; x++) {
for (int y=0; y<nc; y+= fftvis->nChannels) {
data[y] = 10*log(sqrt((pow(fft[k++][0],2) + pow(fft[k++][1],2))));
//k+=1;
} // end of line
data+= step;
// next line
}
You need to fill each channel’s RGB, but you are stepping over channel data when
y+= fftvis->nChannelsis executed.Also,
data+= step;would skipstepbytes of your data, this is not necessary if you align the processing properly.