0

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

提前非常感谢。

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

图一:分水岭分割后(彩色版):

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);
4

2 回答 2

0

我确认您使用的分水岭肯定有问题。我在自己的库上运行了您的代码,并使用了:一个内部标记(最大的组件,因此角上的叶子被丢弃),一个外部(内部的膨胀),渐变图像。

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

于 2015-09-04T00:16:41.103 回答
0
  • 无法根据分割后的图像提取叶子,因为黄色分量将叶子分割成不同的部分。
  • 此外,根据源代码,我了解您使用的基本分水岭会产生过度分割。使用受约束的分水岭,也称为带标记的分水岭。
  • 想办法共享原始图像和处理后的图像。
于 2015-08-29T07:36:47.343 回答