I have begun (a small project) to calculate the power spectrum of an image in the frequency domain.
So, what I have till now is the following:
%// close all; clear all; %// not generally appreciated
img = imread('ajw_pic.jpg','jpg'); % it is a color image
img = rgb2gray(img); %// change to gray
psd = 10*log10(abs(fftshift(fft2(img))).^2 );
figure(2); clf
mesh(psd)
So far it looks good; I get the mesh plot which resembles the spectra I see in various academic papers.
However, what I am looking for is a graph plot of this power spectra versus the frequency, and I am not entirely sure how to get this frequency vector. I could do for instance:
N=400; %// the image is 400 x 400
f=-N/2:N/2-1; %// possible frequencies?
but I am not convinced this is entirely correct as this gives rise to negative frequencies.
I'd really appreciate if someone could point me in the right direction to plot log frequency versus the power spectrum.
1/400
(given 400is my px), but I do not have anfs
since this is an image? Also, when I fft my 400x400 image, and calculate power, the result is also a 400 x 400 matrix - but, I guess what I want is something of size 1x400 - so that I can plot frequencies and the power spectrum. Or am I being stupid here? – Intort