实验五 图像分割

实验内容

1、分别用Roberts、Prewitt、Sobel三种边缘检测算子,对图像wire.bmp进行水平、垂直及各个方向的边界检测,并将检测结果转化为白底黑线条的方式显示出来;

 

%图像边缘检测

%加载图片并读取图片信息

srcImage=imread('L:\图像处理\实验文件\wire.bmp');

%srcImageInfo=imfinfo('E:\MatlabWorkSpace\实验三边缘检测\image.bmp');%图像为truecolor,首先转化为灰度图

%将图像转化为灰度图

grayImage=rgb2gray(srcImage);

%分别使用Roberts\Sobel\Prewitt\Canny算子进行边缘检测

imageRoberts=edge(grayImage,'roberts');

imageSobel=edge(grayImage,'sobel');

imagePrewitt=edge(grayImage,'prewitt');

imageCanny=edge(grayImage,'canny');

%显示检测图像

subplot(2,3,1);imshow(grayImage);title('原图像');

subplot(2,3,2);imshow(~imageRoberts);title('roberts');

subplot(2,3,3);imshow(~imageSobel);title('sobel');

subplot(2,3,4);imshow(~imagePrewitt);title('prewitt');

subplot(2,3,5);imshow(~imageCanny);title('canny');

 

2、使用手动阈值分割法对bottle图像进行分割,显示分割结果,并分析其优缺点。

subplot(2,2,1);

img = imread('L:\图像处理\实验文件\bottle.png');

imshow(img);

title('原图');

subplot(2,2,[3,4]);

imhist(img);

title('直方图');

[m,n] = size(img);

thresh = 90;

for i = 1:m

   for j = 1:n

      if(img(i,j) > thresh)

         img(i,j) = 255;

      else

         img(i,j) = 0;

      end

   end

end

subplot(2,2,2);

imshow(img);

title('分割图像');

3、对下图A进行处理,得到类似图B的样子;

a=imread('L:\图像处理\实验文件\A.jpg');

%灰度二值图像

a=rgb2gray(a);

%分别使用Roberts\Sobel\Prewitt\Canny算子进行边缘检测

aRoberts=edge(a,'roberts');

aSobel=edge(a,'sobel');

aPrewitt=edge(a,'prewitt');

aCanny=edge(a,'canny');

%imshow()时,使用非~进行黑白色对调

subplot(2,3,1);imshow(a);title('原图像');

subplot(2,3,2);imshow(~aRoberts);title('roberts');

subplot(2,3,3);imshow(~aSobel);title('sobel');

subplot(2,3,4);imshow(~aPrewitt);title('prewitt');

subplot(2,3,5);imshow(~aCanny);title('canny');

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫归棠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值