Image processing with gradient FFT
Show older comments
I have a stack of RGB images and I am trying to find which of those are out of focus in order to remove them. I do not want to correct the focus I just want to find a way to remove the out of focus images without having to look at the actual images but by using the power spectrum. I have done FFT2 to the image and then used the radial average of the power spectrum to see if there is a difference between the in focus or out of focus but I do not see a difference between the two. I decided to use the gradient of the image instead
[gx,gy]=gradient(image);
g_mag=sqrt((gx.^2)+(gy.^2));
new_fft=fft2(g_mag);
shift_ftt=fftshift(abs(new_fft));
I am not sure if I need to remove the mean or add some zero padding (i have tried with and without those) but when I average the power spectrum I do not get the kind of graph I expect. The way I calculate the radial plot (numpix is how many pixels is the region of image I am working on and numf is how many frequencies i am using):
x = 2*(meshgrid(1:numpix)/numpix)-1;
y = 2*(meshgrid(1:numpix)/numpix)-1;
r1 = sqrt(x.^2 + y.^2);
r1(r1>1) = 0;
r1 = r1*numf;
for i=1:numf
d{i} = find((i-1)<r1 & r1<=i);
end;
for i=1:numf
r(i)=mean(fftshift(abs(new_fft((d{i}))));
end
and what I am trying to plot is the r vs the frequencies,freqs=[1:numf]/numf I expect the graph to look like a bell curve starting from zero, peaking and ending close to zero again. I am not sure what I am doing wrong, anyone has any experience in this?
Accepted Answer
More Answers (0)
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!