您的位置:首页 > 编程语言 > MATLAB

Matlab中图像处理实例:灰度变换,空域滤波,频域滤波,傅里叶变换的实现

2014-04-10 10:36 816 查看
% %图像灰度变换

% f = imread('E:\2013第一学期课程\媒体计算\实验一\Img\Fig0303(a)(breast).tif');

% g1 = imadjust(f, [0 1], [1 0]);

% g2 = imadjust(f, [0.5 0.75], [0 1]); 

% g3 = imadjust(f,[],[],2);

% subplot(2,2,1), imshow(f), title('原始图像');

% subplot(2,2,2), imshow(g1), title('负片图像');

% subplot(2,2,3), imshow(g2), title('亮度扩展图像');

% subplot(2,2,4), imshow(g3), title('gama=2 图像');



% f1 = imread('E:\2013第一学期课程\媒体计算\实验一\Img\Fig0308(a)(pollen).tif');

% figure,imshow(f1);

% figure,imhist(f1)

% ylim('auto')

% f1g1 = histeq (f1, 256);

% figure,imshow(f1g1)

% figure,imhist(f1g1)

% ylim('auto')

%图像空域滤波

close all;

f = imread('E:\2013第一学期课程\媒体计算\实验一\Img\Fig0318(a)(ckt-board-orig).tif');

subplot(2,2,1), imshow(f), title('原始图像');

g = imnoise(f,'salt & pepper',0.2);

subplot(2,2,2), imshow(g), title('噪声图像');

w = [1/9 1/9 1/9; 1/9 1/9 1/9; 1/9 1/9 1/9]

% w = [0.25 0.25; 0.25 0.25]

% g1 = imfilter(f,w, 'replicate')

% subplot(2,2,3), imshow(g1), title('原始图像均值滤波');

g2 = imfilter(g,w, 'replicate')

subplot(2,2,3), imshow(g2), title('均值滤波');

%medfilt2

g3 = medfilt2(g);

subplot(2,2,4), imshow(g3), title('中值滤波');

 

%fspecial

% f = imread('E:\2013第一学期课程\媒体计算\实验一\Img\Fig0316(a)(moon).tif');

% w1 = fspecial('prewitt')

% g1 = f- imfilter(f,w1, 'replicate')



% w2 = fspecial('sobel')

% g2 = f-imfilter(f,w2, 'replicate')



% w3 = fspecial('laplacian',0)

% g3 = f-imfilter(f,w3, 'replicate')



% subplot(2,2,1), imshow(f), title('原始图像');

% subplot(2,2,2), imshow(g1), title('prewitt');

% subplot(2,2,3), imshow(g2), title('sobel');

% subplot(2,2,4), imshow(g3), title('laplacian');

%傅里叶变换 

% f = imread('E:\2013第一学期课程\媒体计算\实验一\Img\Fig0315(a)(original_test_pattern).tif');

% F=fft2(f);  %对图像f进行傅里叶变换,得到的图像大小为P*Q

% s = abs(F);

% Fc=fftshift(F);    %将变换原点移到频率矩形的中心

% S=log(1+abs(Fc));   %对频谱图进行对数变换,以便更好显示频谱

% g=real(ifft2(F));  %对傅里叶频谱进行逆变换,显示效果



% subplot(2,2,1), imshow(s,[]), title('傅里叶变换后图像');

% subplot(2,2,2), imshow(abs(Fc),[]), title('将变换原点移到频率矩形的中心');

% subplot(2,2,3), imshow(S,[]), title('频谱图进行对数变换');

% subplot(2,2,4), imshow(g), title('傅里叶频谱进行逆变换图像');

% figure,imshow(f);

%图像频域滤波

%  f = imread('E:\2013第一学期课程\媒体计算\实验一\Img\Fig0515(a)(base-with-control-points).tif');

%  [m,n] = size(f);

%  F = fft2(f);

%  sig = 10;

%  H = lpfilter('gaussian',m, n, sig);

%  G = H.*F;

%  g1 = real(ifft2(G));

%  %空域高斯滤波

%  w = fspecial('gaussian',500,10)

%  g2 =imfilter(f,w, 'replicate')

%  

%  subplot(1,3,1), imshow(f,[]), title('原始图像');

%  subplot(1,3,2), imshow(g1,[]), title('频域高斯滤波');

%  subplot(1,3,3), imshow(g2,[]), title('空域高斯滤波');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息