fft = fft2(image);%加载图像
fft_shift=fftshift(fft);
power = log(abs(fft_shift));
I=power;
I = (I - min(I(:))) / (max(I(:)) - min(I(:)));
I = im2uint8(I);%imshow(I)与imshow(I,[])存在差异,此处是为了roipoly能够调用频谱图,在频谱图上交互式选取滤波范围
figure;
set (gcf,'Position',[267 308 1498 620])
set (gcf,'Name','低通滤波-请手动选取滤波范围,双击选择区域确定')
subplot(131);imshow(image);title('原图');
subplot(132);title('选取滤波范围');
[B r c]=roipoly(I);%交互式选取滤波范围
imshow(power.*B,[])
title('滤波后频谱');
subplot(133);title('低通滤波结果');
imshow(ifft2(ifftshift( fft_shift.*B)))
pause(1)
figure;
set (gcf,'Position',[267 308 1498 620])
set (gcf,'Name','高通滤波-请手动选取滤波范围,双击选择区域确定')
subplot(131);imshow(image);title('原图');
subplot(132);title('选取滤波范围');
[B r c]=roipoly(I);%交互式选取滤波范围
imshow(power.*~B,[])
title('滤波后频谱');
subplot(133);title('高通滤波结果');
imshow(ifft2(ifftshift( fft_shift.*~B)))
pause(1)
figure;
set (gcf,'Position',[267 308 1498 620])
set (gcf,'Name','带通滤波-请手动选取滤波范围,先选大范围,再选小范围,双击选择区域确定')
subplot(131);imshow(image);title('原图');
subplot(132);title('选取滤波范围');
[Bmax r c]=roipoly(I);%交互式选取滤波范围
[Bmin r c]=roipoly(I);%交互式选取滤波范围
B = Bmax & ~Bmin;
imshow(power.*B,[])
title('滤波后频谱');
subplot(133);title('带通滤波结果');
imshow(ifft2(ifftshift( fft_shift.*B)))