我有几张相同物体的图像,我想根据清晰度排名。比如说,对焦点的质量进行排名。
从理论上我知道,当你使图像不那么锐利时,你就会失去高频。为了测试这一点,我将三个图像转换为频域:
很明显,由于噪音,模糊的图像具有更均匀的更高频率。但是量化这个的好方法是什么? 我试图在距离最亮像素一定距离处获得像素的平均值,但这并没有显示出太大差异
我如何使用此方法查找最清晰的图片。
以下是我用来制作上述图片的代码:
%make gaussian filter
S=10;P=1.5;
x = [-S/2:1:S/2];
x = exp(-x.^2/(2*P^2));
filt = x'*x;filt = filt/sum(filt(:));
%laplacian kernel
LapK = [0 1 0; 1 -4 1 ; 0 1 0];
%get demo image
Iorg = imread('peppers.png');
Iorg = mean(Iorg,3);
Iorg = Iorg./max(Iorg(:));
%mesh grid
[X,Y]=meshgrid(1:size(Iorg,2),1:size(Iorg,1));
R = sqrt(X.^2+Y.^2);
Rmax = min(size(Iorg)./2);
%Add noise and fourier transform
I = Iorg+randn(size(Iorg))*0.01;I = I./max(I(:));
L = conv2(I,LapK); L1 = max(L(:));
F = fft2(Iorg);
%Radial mean
RadM1=nan([1,Rmax]);
for ct = 1:Rmax
RadM1(ct) = mean(abs(F(R<=ct&R>(ct-1))));
end
figure(1);clf;colormap jet
subplot(3,3,1);imagesc(repmat(Iorg,[1,1,3]));axis image off;title('image');
subplot(3,3,2);imagesc(log(abs(fftshift(F))),[-4 10]);axis image off;title('fourier transform');
subplot(3,3,3);plot(1:Rmax,log(RadM1),'.-');title('radial mean');
ylabel('log(|F|)');ylim([2 12])
%filter
I=conv2(Iorg, filt, 'same');
%Add noise and fourier transform
I = I+randn(size(Iorg))*0.01;I = I./max(I(:));
L = conv2(I,LapK); L2 = max(L(:));
F = fft2(I);
%Radial mean
RadM2=nan([1,Rmax]);
for ct = 1:Rmax
RadM2(ct) = mean(abs(F(R<=ct&R>(ct-1))));
end
subplot(3,3,4);imagesc(repmat(I,[1,1,3]));axis image off;title('filtered once');
subplot(3,3,5);imagesc(log(abs(fftshift(F))),[-4 10]);axis image off;title('fourier transform');
subplot(3,3,6);plot(1:Rmax,log(RadM2),'.-');title('radial mean');
ylabel('log(|F|)');ylim([2 12])
%filter twice
I=conv2(Iorg, filt, 'same');I=conv2(I, filt, 'same');
%Add noise and fourier transform
I = I+randn(size(Iorg))*0.01; I = I./max(I(:));
L = conv2(I,LapK); L3 = max(L(:));
F = fft2(I);
%Radial mean
RadM3=nan([1,Rmax]);
for ct = 1:Rmax
RadM3(ct) = mean(abs(F(R<=ct&R>(ct-1))));
end
subplot(3,3,7);imagesc(repmat(I,[1,1,3]));axis image off;title('filtered twice');
subplot(3,3,8);imagesc(log(abs(fftshift(F))),[-4 10]);axis image off;title('fourier transform');
subplot(3,3,9);plot(1:Rmax,log(RadM3),'.-');title('radial mean');
ylabel('log(|F|)');ylim([2 12])
xlabel('radius(pix)');
fprintf(1,'1: %.2f \n2: %.2f \n3: %.2f\n',L1,L2,L3)
结果
1:1.04
2:0.35
3:0.27
[edit]这确实是重复的。在这种情况下,使用laplacian内核进行卷积并寻找最大值。 [/编辑]