• 大小: 2KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: Matlab
  • 标签:

资源简介

matlab编写的分水岭算法实验代码,用于图像分割处理,针对连接在一起的物体图像,进行分割效果较好

资源截图

代码片段和文件信息

rgb = imread(‘F:\matlab\图片\2222.jpg‘);
I=rgb2gray(rgb);
subplot(231)imshow(rgb) title(‘原图‘);
hy = fspecial(‘sobel‘);
hx = hy‘;
Iy = imfilter(double(I) hy ‘replicate‘);
Ix = imfilter(double(I) hx ‘replicate‘);
gradmag = sqrt(Ix.^2 + Iy.^2);
subplot(232)imshow(gradmag[]) title(‘梯度幅值图像‘);
 
 
se = strel(‘disk‘ 20);
Ie = imerode(I se);
Iobr = imreconstruct(Ie I);
%subplot(333)imshow(Iobr) title(‘基于开的重建图像‘);


Iobrd = imdilate(Iobr se);
Iobrcbr = imreconstruct(imcomplement(Iobrd) imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
subplot(233)imshow(Iobrcbr) title(‘基于开闭的重建图像‘);
%subplot(335); imshow(fgm); title(‘局部极大图像‘);

It1 = rgb(: : 1);
It2 = rgb(: : 2);
It3 = rgb(: : 3);
It1(fgm) = 255; It2(fgm) = 0; It3(fgm) = 0;
I2 = cat(3 It1 It2 It3);
%subplot(234); imshow(I2); title(‘局部极大

评论

共有 条评论