图像图像去噪、滤波 、边缘检测 matlab实现

I=imread('C:\Users\Administrator\Desktop\孔雀1.jpg');%读取图像
J1=imnoise(I,'gaussian',0,0.0005);%加入均值为0,方差为0.005的高斯噪声
J=rgb2gray(J1);
subplot(2,3,1);imshow(I);
title('原始图像');
subplot(2,3,2); imshow(J);
title('加入高斯噪声之后的图像');
%采用MATLAB中的函数filter2对受噪声干扰的图像进行均值滤波
K1=filter2(fspecial('average',1),J)/255; %模板尺寸为1
K2=filter2(fspecial('average',5),J)/255;% 模板尺寸为5
K3=filter2(fspecial('average',7),J)/255; %模板尺寸为7
K4= filter2(fspecial('average',9),J)/255; %模板尺寸为9
subplot(2,3,3);imshow(K1);
title('改进后的图像1');
subplot(2,3,4); imshow(K2);
title('改进后的图像2');
subplot(2,3,5);imshow(K3);
title('改进后的图像3');
subplot(2,3,6);imshow(K4);
title('改进后的图像4'); 
    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
img=imread('C:\Users\Administrator\Desktop\孔雀1.jpg');%读取图像
imggray=rgb2gray(img);
imggrayfilt=filter2(fspecial('average',1),J)/255;
figure(1)
imshow(imggray);
figure(2)
imhist(imggrayfilt);
figure(3)
imshow(imggrayfilt);
imgbw = im2bw(imggrayfilt,graythresh(imggrayfilt));
figure(4)
imshow(imgbw);
%函数功能:使用最大类间方差法找到图片的一个合适的阈值(threshold)。
%在使用im2bw函数将灰度图像转换为二值图像时,需要设定一个阈值,
%这个函数可以帮助我们获得一个合适的阈值。
%利用这个阈值通常比人为设定的阈值能更好地把一张灰度图像转换为二值图像。

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
I=imread('C:\Users\Administrator\Desktop\孔雀1.jpg');%  提取图像
I=rgb2gray(I);
BW1=edge(I,'sobel'); %用SOBEL算子进行边缘检测
BW2=edge(I,'roberts');%用Roberts算子进行边缘检测
BW3=edge(I,'prewitt'); %用prewitt算子进行边缘检测
BW4=edge(I,'log'); %用log算子进行边缘检测
BW5=edge(I,'canny'); %用canny算子进行边缘检测
%h=fspecial('gaussian',5);
BW6=edge(I,'canny');
figure(1);
subplot(2,3,1), imshow(BW1);
title('sobel edge check');
subplot(2,3,2), imshow(BW2);
title('roberts edge check');
subplot(2,3,3), imshow(BW3);
title('prewitt edge check');
subplot(2,3,4), imshow(BW4);
title('log edge check');
subplot(2,3,5), imshow(BW5);
title('canny edge check');
subplot(2,3,6), imshow(BW6);
title('gasussian&canny edge check');%此为用高斯滤波后Canny算子边缘检测结果
figure(2);
%Egray = uint8(edge(I,'canny'));
%for i = 1:300
%    for j = 1:300
%        if Egray(i,j)==0
%            I(i,j)=0;
%        end
%    end
%%end
%imshow(I);

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
					<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-7f770a53f2.css" rel="stylesheet">
            </div>
I=imread('C:\Users\Administrator\Desktop\孔雀1.jpg');%读取图像
J1=imnoise(I,'gaussian',0,0.0005);%加入均值为0,方差为0.005的高斯噪声
J=rgb2gray(J1);
subplot(2,3,1);imshow(I);
title('原始图像');
subplot(2,3,2); imshow(J);
title('加入高斯噪声之后的图像');
%采用MATLAB中的函数filter2对受噪声干扰的图像进行均值滤波
K1=filter2(fspecial('average',1),J)/255; %模板尺寸为1
K2=filter2(fspecial('average',5),J)/255;% 模板尺寸为5
K3=filter2(fspecial('average',7),J)/255; %模板尺寸为7
K4= filter2(fspecial('average',9),J)/255; %模板尺寸为9
subplot(2,3,3);imshow(K1);
title('改进后的图像1');
subplot(2,3,4); imshow(K2);
title('改进后的图像2');
subplot(2,3,5);imshow(K3);
title('改进后的图像3');
subplot(2,3,6);imshow(K4);
title('改进后的图像4'); 
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

猜你喜欢

转载自blog.csdn.net/qq_32790593/article/details/83864720