MATLAB: Fftshift of an image

fft2fftshiftimage processing

Hi all,
I'm trying out to find the wavelength of the wave seen in this image: http://www.flickr.com/photos/66468892@N07/6052890522/
I did the fftshift of the red channel [ im(:,:,1) ] and got this image: http://www.flickr.com/photos/66468892@N07/6052339583/
I did the fftshift of the grayscale [ rgb2gray ] and got this image: http://www.flickr.com/photos/66468892@N07/6052365079/
I think the first pair of lateral peaks on either side of the DC peak, in second and third images, corresponds to the grid lines (a grid pattern can be seen in the first image). How could I correlate the co-ordinates of the next pair of lower peaks to the image? Does those peaks correspond to some characteristic of the wave seen in the first image?
Thanks.

Best Answer

In order to use the DFT to determine the wavelength of the pattern in the image, you will need one key piece of information: some way to relate the size of the pixels in the image to an actual length in a physical unit of measure (for example: inches, centimeters, or millimeters). More specifically, you will need to know (or at least assume) a value for the number of pixels per unit of physical distance.
I will assume for now that you would like to know the wavelength in units of centimeters. Then you would need a value for the number of pixels per centimeter in the x-direction, and likewise in the y-direction (these two values could be the same or different, depending on the scaling of the image).
Let's call these parameters the pixel sampling rates for the X-direction and the Y-direction, respectively, and use the MATLAB variables Fs_x and Fs_y to represent them. The units of measure for these variables are pixels per centimeter. I will assume the following values:
Fs_x = 50; % pixels per centimeter
Fs_y = 40;
We can then compute the pixel sizes in each direction as the reciprocal of the pixel sampling rates:
dx = 1/Fs_x; % centimeters per pixel
dy = 1/Fs_y;
We can then compute a linear distance scale for the X- and Y-axes of the cropped image:
[ M, N, ~ ] = size(cimg); % pixels
x = dx*(0:N-1)'; % centimeters
y = dy*(0:M-1)';
Next, we compute the frequency increments for both X and Y:
dFx = Fs_x/N; % cycles per centimeter

dFy = Fs_y/M;
Finally, we can create a frequency domain array for both X and Y:
Fx = (-Fs_x/2:dFx:Fs_x/2-dFx)'; % cycles per centimeter
Fy = (-Fs_y/2:dFy:Fs_y/2-dFy)';
Almost there (whew!). The last piece is to use fft2 and fftshift to compute the 2D DFT of the image, and then to display the resulting spectral images using Fx and Fy to represent the X- and Y- axes, respectively. From there, you should be able to find the peak values in the spectrum in both directions. The wavelength in each direction is then the reciprocal of the frequencies associated with the peak values.
One other thing: it probably makes sense to remove the DC component of the cropped image prior to computing the DFT. That way, the peaks in the spectrum will show up much more clearly (since they will not have to compete for attention with the DC value).
HTH.
Best,
Rick
Related Question