導航:首頁 > 編程語言 > 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的代碼相關的資料

熱點內容
pkpm能轉低版本 瀏覽:725
c程序設計課件 瀏覽:327
qq炫舞客戶端怎麼修復工具 瀏覽:537
結算需要cad源文件嗎 瀏覽:446
編程在哪裡簽到 瀏覽:472
什麼網站能看美女直播 瀏覽:148
linux生成excel格式的文件 瀏覽:230
win10開key文件 瀏覽:527
如何看待網路流行用語作文 瀏覽:296
xpsp1升級到sp3打補丁360 瀏覽:389
r語言怎麼讀取txt數據 瀏覽:114
壓縮文件管用嗎 瀏覽:410
華為官網app圖標是哪個 瀏覽:603
中標麒麟共享主機的文件路徑 瀏覽:309
滴答出行app怎麼下載 瀏覽:990
蘋果5怎麼屏幕變色了 瀏覽:753
怎麼把u盤文件改成可執行程序 瀏覽:915
ios902升級死機 瀏覽:180
ps什麼文件格式能轉成pdf 瀏覽:218
怎麼設置qq群的名稱 瀏覽:352

友情鏈接