图像的空域增强
J = imnoise(I,'salt & pepper',0.05);
K= imnoise(I,'gaussian',0.01,0.01);
subplot(132);imshow(J);title('Salt&pepper noise');
subplot(133);imshow(K);title('gaussian noise');
4)运用for循环,将加有椒盐噪声的图像进行10次,20次均值滤波,查看其特点,显示均值处理后的图像(提示:利用fspecial函数的’average’类型生成均值滤波器)。
figure;
I=imread('coins.jpg');
J = imnoise(I,'salt & pepper',0.05);
H= fspecial('gaussian',[3 3],0.5);
gaussian = imfilter(I,H,'replicate');
subplot(224);imshow(gaussian);title('gaussian imag');
3)使用函数imfilter时,分别采用不同的填充方法(或边界选项,如零填充、’replicate’、’symmetric’、’circular’)进行低通滤波,显示处理后的图像。
subplot(232),imshow(K1);title('laplacian operator 5*5 ');
K2=conv2(T,w2,'same');
subplot(233),imshow(K2);title('laplacian operator 9*9 ');
K3=conv2(T,w3,'same');
w = ones(n);
x = ceil(n/2);
w(x, x) = -1 * (n * n - 1);
end
3)分别采用5×5,9×9大小的拉普拉斯算子对blurry_moon.tif进行锐化滤波,观察其有何不同,要求在同一窗口中显示。
w1 = genlaplacian(5);
w2 = genlaplacian(9);
评语:
h=fspecial('average');
J1=imfilter(J,h);
for i=1:10
J1=imfilti=1:20
J2=imfilter(J,h);
end
subplot(131);imshow(I); title('Original image');
subplot(132);imshow(J1); title('10-Averaging image');
originalRGB = imread('peppers.png');
h = fspecial('motion', 50, 45);
RGB = imfilter(originalRGB, h);
boundaryReplicateRGB = imfilter(originalRGB, h, 'replicate');
二、实验内容
1)实现平滑空间滤波
2)实现锐化空间滤波
三、实验过程(步骤、命令)及结果(截图、源程序)
1、平滑空间滤波
1)读出coins.jpg这幅图像,给这幅图像分别加入椒盐噪声和高斯噪声后并与前一张图显示在同一图像窗口中。
figure;
I=imread('coins.jpg');
subplot(131);imshow(I); title('Original image');
boundary0RGB = imfilter(originalRGB, h, 0);
boundarysymmetricRGB = imfilter(originalRGB, h, 'symmetric');
boundarycircularRGB = imfilter(originalRGB, h, 'circular');
w3 = genlaplacian(15);
w4 = genlaplacian(25);
I=imread('blurry_moon.tif');
T=double(I);
subplot(231),imshow(T,[]);title('Original Image');
K1=conv2(T,w1,'same');
2)对加入噪声图像选用不同的平滑(低通)模板做运算,对比不同模板所形成的效果,要求在同一窗口中显示。
figure;
I=imread('coins.jpg');
subplot(221);imshow(I);title('original image');
H = fspecial('sobel');
Sobel = imfilter(I,H,'replicate');
subplot(234),imshow(K3);title('laplacian operator 15*15 ');
K4=conv2(T,w4,'same');
subplot(235),imshow(K4);title('laplacian operator 25*25 ');
四、存在问题及解决方法
subplot(324);imshow(boundary0RGB);title('0-padding image');
subplot(325);imshow(boundarysymmetricRGB);title('symmetric image');
subplot(326);imshow(boundarycircularRGB);title('circular image');
2、锐化空间滤波
1)读出blurry_moon.tif这幅图像,采用3×3的拉普拉斯算子w = [ 1,1,1; 1,–8,1; 1,1,1]对其进行滤波。
I=imread('blurry_moon.tif');
T=double(I);
subplot(121),imshow(T,[]);title('Original Image');
实验报告
2012年11月22日第9、10节综合楼426号室
进入实验室
时间
进入时仪器
设备状况
离开实验室
时间
离开时仪器
设备状况
机器号
15:30
良好
17:00
良好
4-54
实验项目名称
图像的空域增强
一、实验目的
1)掌握图像滤波的基本定义及目的。
2)理解空间域滤波的基本原理及方法。
3)掌握进行图像的空域滤波的方法。
J1=imfilter(J,h);
J2=medfilt2(J);
subplot(131);imshow(I); title('Original image');
subplot(132);imshow(J1); title('Averaging image');
subplot(133);imshow(J2); title('median image');
w =[1,1,1; 1,-8,1; 1,1,1];
K=conv2(T,w,'same');
subplot(122),imshow(K);title('laplacian transform');
2)编写函数w = genlaplacian(n),自动产生任一奇数尺寸n的拉普拉斯算子
function w = genlaplacian(n)
subplot(321);imshow(originalRGB);title('original image');
subplot(322);imshow(RGB);title('motion blurred image');
subplot(323);imshow(boundaryReplicateRGB);title('replicate image');
subplot(222);imshow(Sobel);title('sobel image');
H = fspecial('laplacian',0.4);
lap = imfilter(I,H,'replicate');
subplot(223);imshow(lap);title('laplacian image');
subplot(133);imshow(J2); title('20-Averaging image');
5)对加入椒盐噪声的图像分别采用均值滤波法,和中值滤波法对有噪声的图像做处理,要求在同一窗口中显示结果。
figure;
I=imread('coins.jpg');
h=fspecial('average');