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

时间:2015-08-28 18:37:34

标签: matlab image-processing image-segmentation watershed

在我应用分水岭分割后,我想从图像中提取剩余的叶子,只有我想要没有像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)

  • 根据分割的图像不可能提取叶子,因为黄色成分会切割不同部分的叶子。
  • 此外,根据源代码,我了解您使用产生过度分割的基本分水岭。使用受限制的流域,也称为带标记的流域。
  • 找到一种在处理后共享原始图像和图像的方法。

答案 1 :(得分:0)

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

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

相关问题