几个问题:
PPT贼爽特别爽爽到爆炸的干货课件
实验目的:
掌握空间滤波的基本原理;
能够利用MATLAB通过滤波器实现图像平滑和锐化操作,
熟悉不同滤波器的应用场合;
掌握图像卷积操作和相关操作的区别;
利用imnoise函数对图像添加噪声;
熟悉matlab的imfilter, fspecial, medfilt2, ordfilt2的用法;
实验内容:
读出一幅图像,分别对该图像加入高斯和椒盐噪声,然后利用均值滤波器,高斯滤波器,圆盘滤波器,以及中值滤波器对图像进行降噪处理,对比几种滤波器去噪效果并分析。
读出一副图像,利用sobel算子,laplacian算子,log算子对图像进行滤波;然后将该图像加入噪声,再次利用上述算子对噪声图像进行滤波,对比几种算子锐化滤波的特点,并分析。
代码
i=imread('C:\Users\liulang\Desktop\lb.jpg');%读入图像
g=rgb2gray(i);%变成灰度
g_gaussian=imnoise(g,'gaussian');%加入高斯噪声
g_salt_pepper=imnoise(g,'salt & pepper');%加入椒盐噪声
figure(1),subplot(221),imshow(i),title('显示原图');
subplot(222),imshow(g),title('显示灰度图');
subplot(223),imshow(g_gaussian),title('高斯噪声');
subplot(224),imshow(g_salt_pepper),title('椒盐噪声');
%分别对高斯噪声和椒盐噪声进行处理
%先是对高斯噪声处理
w_a=fspecial('average');%均值滤波器
w_g=fspecial('gaussian');%高斯滤波器
w_d=fspecial('disk');%圆盘滤波器
g_m1=medfilt2(g_gaussian,[3 3],'zeros');%中值滤波器
g_a1 = imfilter (g_gaussian, w_a, 'conv', 'replicate');
g_g1 = imfilter (g_gaussian, w_g, 'conv', 'replicate');
g_d1 = imfilter (g_gaussian, w_d, 'conv', 'replicate');
figure(2),subplot(221),imshow(g_m1),title('中值-高斯噪声');
subplot(222),imshow(g_a1),title('均值-高斯噪声');
subplot(223),imshow(g_g1),title('高斯-高斯噪声');
subplot(224),imshow(g_d1),title('圆盘-高斯噪声');
%再是对椒盐噪声处理
g_m2=medfilt2(g_salt_pepper,[3 3],'zeros');%中值滤波器
g_a2 = imfilter (g_salt_pepper, w_a, 'conv', 'replicate');
g_g2 = imfilter (g_salt_pepper, w_g, 'conv', 'replicate');
g_d2 = imfilter (g_salt_pepper, w_d, 'conv', 'replicate');
figure(3),subplot(221),imshow(g_m2),title('中值-椒盐');
subplot(222),imshow(g_a2),title('均值-椒盐');
subplot(223),imshow(g_g2),title('高斯-椒盐');
subplot(224),imshow(g_d2),title('圆盘-椒盐');
w_s = fspecial ('sobel')%sobel算子
w_p=fspecial('prewitt')%prewitt算子
w_l= fspecial ('laplacian',0.4);%laplacian算子
w_log= fspecial ('log',[3 3], 0.5);%log算子
%加入椒盐噪声%然后加入噪声
g_s1 = imfilter (g, w_s, 'conv', 'replicate');%sobel算子滤波
g_p1=imfilter(g,w_p,'conv','replicate');%prewitt算子滤波
g_l1 = imfilter (g, w_l, 'conv', 'replicate');%laplacian算子滤波
g_log1 = imfilter (g, w_log, 'conv', 'replicate');%log算子滤波
figure(4),subplot(221),imshow(g_s1),title('sobel算子滤波');
subplot(222),imshow(g_p1),title('prewitt算子滤波');
subplot(223),imshow(g_l1 ),title('laplacian算子滤波');
subplot(224),imshow(g_log1),title('log算子滤波');
g_s2 = imfilter (g_salt_pepper, w_s, 'conv', 'replicate');%sobel算子滤波
g_p2=imfilter(g_salt_pepper,w_p,'conv','replicate');%prewitt算子滤波
g_l2 = imfilter (g_salt_pepper, w_l, 'conv', 'replicate');%laplacian算子滤波
g_log2 = imfilter (g_salt_pepper, w_log, 'conv', 'replicate');%log算子滤波
figure(5),subplot(221),imshow(g_s2),title('sobel算子滤波-椒盐');
subplot(222),imshow(g_p2),title('prewitt算子滤波-椒盐');
subplot(223),imshow(g_l2 ),title('laplacian算子滤波-椒盐');
subplot(224),imshow(g_log2),title('log算子滤波-椒盐');
figure(6),subplot(221),imshow(g_s2,[]),title('sobel算子滤波-椒盐');
subplot(222),imshow(g_p2),title('prewitt算子滤波-椒盐');
subplot(223),imshow(g_l2 ),title('laplacian算子滤波-椒盐');
subplot(224),imshow(g_log2),title('log算子滤波-椒盐');