二维图像的傅里叶变换

背景

Matlab Example

img=rgb2gray(imread("image1.jpg"));
freq=fftshift(fft2(im2double(img)));
fout=log(abs(freq)+1.001);
subplot(2,1,1),imshow(img);
subplot(2,1,2),imshow(fout,[]);

Play More

f=zeros(32);
f(14,16)=1;
f(18,16)=1;
img=fftshift(fft2(f));
iout=abs(img);
subplot(2,2,1),imshow(f);
subplot(2,2,2),imshow(iout,[]);

f=zeros(32);
f(14,14)=1;
f(18,18)=1;
img=fftshift(fft2(f));
iout=abs(img);
subplot(2,2,3),imshow(f);
subplot(2,2,4),imshow(iout,[]);

Naive 的滤波示例

img=imresize(rgb2gray(imread("image1.jpg")),0.2);
freq=fftshift(fft2(im2double(img)));
fout=log(abs(freq)+1.001);
subplot(2,2,1),imshow(img);
subplot(2,2,2),imshow(fout,[]);

[h,w]=size(freq);
cx=w/2;
cy=h/2;
for y=1:h
    for x=1:w
        dx=abs(x-cx);
        dy=abs(y-cy);
        if dx>=10 || dy>=10
            freq(y,x)=0;
        end
    end
end

fout2=log(abs(freq)+1.001);
subplot(2,2,3),imshow(fout2,[]);

img2=mat2gray(abs(ifft2(ifftshift(freq))));
subplot(2,2,4),imshow(img2,[]);

原文地址:https://www.cnblogs.com/mollnn/p/14949678.html