导航:首页 > 编程语言 > 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的代码相关的资料

热点内容
如何检查无线网络驱动是否正常 浏览:468
百度网盘来自分享的文件在哪里 浏览:127
如何发视频到腾讯视频文件夹里 浏览:510
微信打开cad外部文件找不到 浏览:882
平板可以打开各种文件后缀的软件 浏览:531
苹果微信文件怎么全选 浏览:749
手机里之前打开过的文件在哪里找 浏览:685
cad能看word文件吗 浏览:719
12306火车票系统后台数据库 浏览:570
js翻译德语 浏览:33
从哪里可以下载a股的数据 浏览:437
逻辑文件名和物理文件名关系 浏览:66
怎么查一个网站的外链 浏览:675
linux下db2安装时版本选择 浏览:738
汇编编程用哪个软件 浏览:486
仙乐下的歌在文件管理哪里 浏览:477
115网盘解析工具2014 浏览:371
内圆弧铣刀怎么编程 浏览:410
记事本文件转word格式对齐 浏览:300
excel删除恢复文件 浏览:290

友情链接