Image processing with gradient FFT
6 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Eric
2013 年 12 月 5 日
You should check out Focus Measure in the File Exchange at
This has a variety of Fourier focus methods already implemented. You can either use one of these or compare your code against these.
Good luck,
Eric
2 件のコメント
Eric
2013 年 12 月 6 日
編集済み: Eric
2013 年 12 月 6 日
You might check out this code again. For example, consider the 'DCTE' option. It calculates the 2D discrete cosine transform, takes the magnitude squared of that, and then looks at some metrics of that. That's a lot like finding the power spectrum and then analyzing it.
You could also look at the reference: [Shen2006] Shen, C. & Chen, H. Robust focus measure for low-contrast images. 2006.
You could do a cited-reference search to see who's referenced this work and perhaps tweaked things a bit relative to what Shen did.
Anyways, I was trying to address your initial problem: "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." Unfortunately, I don't have time to work through your code for the radial plot. But determining focus from imagery is a topic that has been worked a great deal and perhaps a better place to start is what folks have already tried.
Good luck,
Eric
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Fourier Analysis and Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!