2)对加入的噪声图像选用不同的平滑处理模板运算,对比不同的模板所形成的效果 close all
I=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp'); J=imnoise(I,'salt & pepper',0.5); subplot(1,4,1);imshow(J); H=fspecial('sobel');
sobel=imfilter(I,H,'replicate'); subplot(1,4,2);imshow(sobel); >> H=fspecial('laplacian',0.4); lap=imfilter(I,H,'replicate'); >> subplot(1,4,3);imshow(lap); >> H=fspecial('gaussian',[3 3],0.5); gaussian=imfilter(I,H,'replicate'); >> subplot(1,4,4);imshow(gaussian);
3)使用函数imfilter时,采用不同的填充方法进行的滤波,显示处理后的图像 originalRGB=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp'); subplot(2,3,1);imshow(originalRGB); h=fspecial('motion',50,45);
filteredRGB=imfilter(originalRGB,h); subplot(2,3,2); imshow(filteredRGB);
boundaryReplicateRGB=imfilter(originalRGB,h,'replicate'); subplot(2,3,3);imshow(boundaryReplicateRGB); boundary0RGB=imfilter(originalRGB,h,0); subplot(2,3,4); imshow(boundary0RGB);
boundarysymmetricRGB=imfilter(originalRGB,h,'symmetric'); subplot(2,3,5);imshow(boundarysymmetricRGB);
boundarycircularRGB=imfilter(originalRGB,h,'circular'); subplot(2,3,6);imshow(boundarycircularRGB)
4)应用for循环,将加有椒盐噪声的图像进行10次、20次均值滤波,查看其特点,显示处理后的图像
I=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp'); J=imnoise(I,'salt & pepper',0.5); subplot(1,3,1);imshow(J) h=fspecial('average'); for i=1:10
J1=imfilter(J,h); end
subplot(1,3,2);imshow(J1) for i=1:20
J2=imfilter(J,h); end
subplot(1,3,3);imshow(J2)
由图可见,20次滤波后的效果明显好于10次的滤波的,但是模糊程度增加。
5)对加入椒盐噪声的图像分别采取均值滤波和中值滤波法对有噪声的图像做处理,要求在同一窗口显示结果
I=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp');
J=imnoise(I,'salt & pepper',0.5); >> subplot(1,3,1);imshow(J) >> h=fspecial('average'); >> J2=imfilter(J,h);
>> subplot(1,3,2);imshow(J2) >> J3=medfilt2(J);
>> subplot(1,3,3);imshow(J3)
从上图可以看出,对于椒盐噪声污染的图像处理,中值滤波效果要明显好于均值滤波,经均值滤波器处理后的图像比均值滤波器中结果图像更加模糊。
6)设计平滑空间滤波器,并将对噪声进行处理,显示处理后的结果 close all
I=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp'); J=imnoise(I,'salt & pepper',0.5);
domain=1/25*[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1]; K1=ordfilt2(J,5,domain); subplot(1,2,1);imshow(J) subplot(1,2,2);imshow(K1)
掩模值为w=1/25*[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1]; close all
I=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp'); J=imnoise(I,'salt & pepper',0.5);
domain=[0 0 8 0 0;0 0 8 0 0;8 8 8 8 8;0 0 8 0 0;0 0 8 0 0];
K1=ordfilt2(J,5,domain); subplot(1,2,1);imshow(J) subplot(1,2,2);imshow(K1)
掩模值为w=[0 0 8 0 0;0 0 8 0 0;8 8 8 8 8;0 0 8 0 0;0 0 8 0 0]; 2.锐化空间滤波器
1)3×3的拉普拉斯算子滤波
I=imread('C:\\Program Files\\MATLAB\\R2009a\\work\\lena','bmp'); >> T=double(I);
>> subplot(1,2,1),imshow(T,[]);title('original Image'); >> w=[1,1,1;1,-8,1;1,1,1]; >> K=conv2(T,w,'same');
>> subplot(1,2,2),imshow(K);
2)奇数尺寸拉普拉斯算子随机产生函数 close all n=5;
w=ones(n); x=ceil(n/2);
w(x,x)=-1*(n*n-1)
相关推荐: