例一:去除低频信息,保留高频信息。高频信息代表边界,实现边界提取。
效果图
源码
close;
clear;
I = imread('A11.png');
[a,b]=size(I);
F = (fftshift(fft2(I)));
% H = zeros(a,b);
H = ones(a,b);
% c=29;d=79;
e=5;f=15;
% H(25:35,75:85) = 1;
% H(a/2-c:a/2+c,b/2-d:b/2+d) = 1;
H(a/2-e:a/2+e,b/2-f:b/2+f) = 0;
% H(10:50,50:110) = 0;
% H(15:45,60:100) = 0;
Fp = F.*H;
iF = ifft2(ifftshift(Fp));
iF = uint8(iF);
figure(1);
subplot(221);imshow(I);%原图
subplot(222);imshow(F);%原图频谱
subplot(223);imshow(iF,[18,19]);%滤波后原图
subplot(224);imshow(Fp);%滤波后频谱
例二:去除雀斑所在频率的信号,进行美颜
效果图
源码
close;
clear;
I = imread('雀斑.jpg');
I = rgb2gray(I);
[a,b] = size(I);
c=60;d=60;
e=40;f=40;
F = (fftshift(fft2(I)));
% H = ones(a,b);
% H(a/2-c:a/2+c,b/2-d:b/2+d) = 0;
% H = zeros(a,b);
% H(a/2-c:a/2+c,b/2-d:b/2+d) = 1;
H = ones(a,b);
H(a/2-c:a/2+c,b/2-d:b/2+d) = 0;
H(a/2-e:a/2+e,b/2-f:b/2+f) = 1;
% H(25:35,75:85) = 1;
% H(10:50,50:110) = 0;
% H(15:45,60:100) = 0;
Fp = F.*H;
iF = ifft2(ifftshift(Fp));
iF = uint8(iF);
figure(1);
subplot(221);imshow(I);%原图
subplot(222);imshow(F);%原图频谱
subplot(223);imshow(iF);%滤波后原图
subplot(224);imshow(Fp);%滤波后频谱