图像去噪、滤波 、边缘检测 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'); 
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函数将灰度图像转换为二值图像时,需要设定一个阈值,
%这个函数可以帮助我们获得一个合适的阈值。
%利用这个阈值通常比人为设定的阈值能更好地把一张灰度图像转换为二值图像。
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);
  • 3
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值