首页 文章

在matlab中分水岭分割后提取叶片

提问于
浏览
0

在我应用分水岭分割后,我想从图像中提取剩余的叶子,只有我想要没有像image-2这样的背景 . 请你帮帮我 . 非常感谢 . 我在下面附上我的代码 . 我是stackoverflow的新手,因此我不允许发布图片 . 我在mathworks中询问了相同的qustion,如果你愿意,可以从那里查看图片 .

非常感谢提前 .

http://www.mathworks.com/matlabcentral/answers/237106-extracting-leaf-from-background

image-1:分水岭分割后(彩色版):

image-2:图像;

我的代码:

% I -- intensity image
  % Gmag -- gradient mag.
      se = strel('disk', 30);
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I);
figure
imshow(Iobr), title('Opening-by-reconstruction (Iobr)')
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
figure
imshow(Iobrcbr), title('Opening-closing by reconstruction (Iobrcbr)')
fgm = imregionalmax(Iobrcbr);
figure
imshow(fgm), title('Regional maxima of opening-closing by reconstruction (fgm)')
% modify area 
I2 = I;
I2(fgm) = 255;
figure
imshow(I2), title('Regional maxima superimposed on original image (I2)')
se2 = strel(ones(10,10));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 100);
I3 = I;
I3(fgm4) = 255;
figure
imshow(I3)
title('Modified regional maxima superimposed on original image (fgm4)')
% background markers
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
figure
imshow(bw), title('Thresholded opening-closing by reconstruction (bw)')
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
figure
imshow(bgm), title('Watershed ridge lines (bgm)')
gradmag2 = imimposemin(Gmag, bgm | fgm4);
L = watershed(gradmag2);
I4 = I;
I4(imdilate(L == 0, ones(3, 3)) | bgm | fgm4) = 255;
figure
imshow(I4)
title('Markers and object boundaries superimposed on original image (I4)')
Lrgb = label2rgb(L, 'jet', 'w', 'shuffle');
figure
imshow(Lrgb)
title('Colored watershed label matrix (Lrgb)')
figure
imshow(I)
hold on
himage = imshow(Lrgb);
himage.AlphaData = 0.3;
title('Lrgb superimposed transparently on original image')


props = regionprops(L);
[~,ind] = max([props.Area]);
imshow(L == ind);

2 回答

  • 0
    • 根据分割的图像不可能提取叶子,因为黄色成分会在不同的部分切割叶子 .

    • 此外,根据源代码,我知道你使用了一个产生过分割的基本分水岭 . 使用受限制的流域,也称为带标记的流域 .

    • 找到一种在处理后共享原始图像和图像的方法 .

  • 0

    我确认您使用的分水岭确实存在问题 . 我在我自己的库上运行你的代码,我使用:一个内部标记(最大的组件,因此拐角处的叶子被丢弃),一个外部(内部的扩张),渐变图像 .

    这是我的结果:www.thibault.biz/StackOverflow/ResultLeaf.png . 所以只有一个组件,因为我只使用一个内部标记 . 它并不完美,但已经更接近并且更容易进行后期处理 .

相关问题