how can i blur an image by removing high frequencies of it's DFT

Hello everyone, I'm trying to blur an image by removing the high frequencies from the DFT of that image. after reading the image i used the fft command, now i have the frequencies but can't figure out how to remove the high ones
any suggestion??

 採用された回答

David Young
David Young 2012 年 1 月 1 日

0 投票

There's a demo that does this here. Other such demos are available also if you look for them.

2 件のコメント

hanan Sh
hanan Sh 2012 年 1 月 2 日
thanks David your demo was helpful, i have one question though,
those lines ....
sigmaf = 10;
mask(1:N/2+1) = exp(-(f/(2*sigmaf)).^2);
mask(N:-1:N/2+2) = mask(2:N/2);
are they supposed to calculate the Gaussian mask???
David Young
David Young 2012 年 1 月 2 日
Hi. Yes, that's what they do. The second line actually computes the Gaussian, and the third line reflects it to make the correct symmetry for a the DFT of a real signal.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 1 月 1 日

0 投票

zero them in the dft.

2 件のコメント

hanan Sh
hanan Sh 2012 年 1 月 1 日
i tried this. the result was black image
imdft= fft2(im);
for i=1:s(1)
for j=1:s(2)
for k=1:s(3)
if (imdft (i ,j ,k)> 0)
imdft (i ,j ,k)== 0;
end
end
end
end
imdft = uint8(ifft2(imdft));
figure, imshow(imdft);
Dr. Seis
Dr. Seis 2012 年 1 月 2 日
You are using a logical equals "==" instead of an "=".

サインインしてコメントする。

Dr. Seis
Dr. Seis 2012 年 1 月 1 日

0 投票

I modified an example I posted earlier. It generates a random 2D image and then applies a simple low-pass filter (i.e., sets high-frequencies beyond some cut-off to 0):
Nx = 32; % Number of samples collected along x dimension
Ny = 64; % Number of samples collected along y dimension
dx = .1; % x increment (i.e., Spacing between each column)
dy = .1; % y increment (i.e., Spacing between each row)
x = 0 : dx : (Nx-1)*dx;
y = 0 : dy : (Ny-1)*dy;
data_spacedomain = randn(Ny,Nx); % random 2D matrix
Nyq_kx = 1/(2*dx); % Nyquist of data in x dimension
Nyq_ky = 1/(2*dy); % Nyquist of data in y dimension
dkx = 1/(Nx*dx); % x Wavenumber increment
dky = 1/(Ny*dy); % y Wavenumber increment
kx = -Nyq_kx : dkx : Nyq_kx-dkx; % x wavenumber
ky = -Nyq_ky : dky : Nyq_ky-dky; % y wavenumber
data_wavenumberdomain = fftshift(fft2(data_spacedomain)); % transform data
data_wavenumberdomain_filtered = data_wavenumberdomain; % copy
% Set high-frequency components with hypot(kx,ky) > 2 to 0
for i1 = 1:Nx
for j1 = 1:Ny
if hypot(kx(i1),ky(j1)) > 2
data_wavenumberdomain_filtered(j1,i1) = 0;
end
end
end
data_spacedomain_filtered = ifft2(ifftshift(data_wavenumberdomain_filtered));
figure;
subplot(3,1,1);
imagesc(kx,ky,abs(data_wavenumberdomain_filtered));
colorbar; v = caxis;
title(sprintf('Wavenumber Domain\n\nFiltered'));
xlabel('kx'); ylabel('ky');
subplot(3,1,2);
imagesc(kx,ky,abs(data_wavenumberdomain));
colorbar; caxis(v);
title('Unfiltered');
xlabel('kx'); ylabel('ky');
subplot(3,1,3);
imagesc(kx,ky,abs(data_wavenumberdomain_filtered-data_wavenumberdomain));
colorbar; caxis(v);
title('Difference');
xlabel('kx'); ylabel('ky');
figure;
subplot(3,1,1);
imagesc(x,y,data_spacedomain_filtered);
colorbar; v = caxis;
title(sprintf('Space Domain\n\nFiltered'));
xlabel('x'); ylabel('y');
subplot(3,1,2);
imagesc(x,y,data_spacedomain);
colorbar; caxis(v);
title('Unfiltered');
xlabel('x'); ylabel('y');
subplot(3,1,3);
imagesc(x,y,data_spacedomain_filtered-data_spacedomain);
colorbar; caxis(v);
title('Difference');
xlabel('x'); ylabel('y');

1 件のコメント

chris crowley
chris crowley 2020 年 5 月 6 日
This code works, but is pretty slow. That for loop and be completely eliminated. Replace the for loop with:
[KX,KY] = meshgrid(ky,kx);
data_wavenumberdomain_filtered(hypot(KX,KY) > 2) = 0;
Instead of looping over each index and checking the if condition, this utilizes MATLABs vectorized functionality. This runs in fractions of a second for the images I have been trying it on as apposed to a few minutes it took the above code.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by