导航:首页 > 编程语言 > imagefiltering的代码

imagefiltering的代码

发布时间:2025-05-22 04:20:10

Ⅰ 用MATLAB实现频域平滑滤波以及图像去噪代码

%%%%%%%%spatial frequency (SF) filtering by low pass filter%%%%%%%%

% the SF filter is unselective to orientation (doughnut-shaped in the SF
% domain).

[FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;

[X map] = imread(filename, fmt); % read image
L = double(X); % transform to double
%%%%%%%%%%%%% need to add (-1)x+y to L

% calculate the number of points for FFT (power of 2)
fftsize = 2 .^ ceil(log2(size(L)));
% 2d fft
Y = fft2(X, fftsize(1), fftsize (2));
Y = fftshift(Y);

% obtain frequency (cycles/pixel)
f0 = floor([m n] / 2) + 1;
fy = ((m: -1: 1) - f0(1) + 1) / m;
fx = ((1: n) - f0(2)) / n;
[mfx mfy] = meshgrid(fx, fy);

% calculate radius
SF = sqrt(mfx .^ 2 + mfy .^ 2);

% SF-bandpass and orientation-unselective filter
filt = SF > k0;

A_filtered = filt .* A; % SF filtering
L_filtered = real(ifft2(ifftshift(A_filtered))); % IFFT
L_filtered = L_filtered(1: size(L, 1), 1: size(L, 2));
%%%%%%%%%%need to add (-1)x + y to L_filtered

% show
figure(1);
clf reset;
colormap gray;

% plot image
subplot(2, 2, 1);
imagesc(L);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('original image');
xlabel('x');
ylabel('y');
imwrite(L, fullfile(FilePath, 'original image.bmp'), 'bmp') ;

% plot amplitude
A = abs(A);
A = log10(A);
% spectral amplitude
subplot(2, 2, 2);
imagesc(fx, fy, A);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('amplitude spectrum');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(A, fullfile(FilePath, 'amplitude spectrum.bmp'), 'bmp') ;

% filter in the SF domain
subplot(2, 2, 3);
imagesc(fx, fy, filt);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('filter in the SF domain');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(filt, fullfile(FilePath, 'filter in SF.bmp'), 'bmp') ;

% filtered image
subplot(2, 2, 4);
imagesc(L_filtered);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('filtered image');
xlabel('x');
ylabel('y');
imwrite(filtered, fullfile(FilePath, 'filtered image.bmp'), 'bmp');

%%%%%%%%%%%%%%%%%median filter%%%%%%%%%%%%%%%%
[FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;

[LNoise map] = imread(filename, fmt); % read image
L = medfilt2(LNoise, [3 3]); % remove the noise with 3*3 block

figure ;
imshow(LNoise) ;
title('image before fitlering') ;
figure
imshow(L)
title('filtered image') ;
imwrite(FilePath, 'filtered image.bmp', bmp)

阅读全文

与imagefiltering的代码相关的资料

热点内容
如何学习下位机编程 浏览:206
日本人如何修复网络 浏览:373
江苏量淘数据怎么样 浏览:422
一组数据2的方差是多少 浏览:535
电脑设置删除显示找不到文件 浏览:454
中国证券app有哪些 浏览:890
天正施工图教程 浏览:428
家庭网络有什么 浏览:126
红米升级系统找不到私密文件 浏览:557
360卫士文件功能描述 浏览:350
魅蓝e2升级yunos 浏览:381
修改ipadID密码 浏览:308
男生去哪里学编程 浏览:772
腻子数据怎么恢复 浏览:699
win10特殊配置文件登录 浏览:55
可视电话电源网站封住了怎么办 浏览:811
如何打印word批注 浏览:152
qq在线表格换成word文件 浏览:138
word文档里找不到文件这栏 浏览:969
如何塑造网站内容公信力 浏览:502

友情链接