首页 文章

用于分割matlab中被遮挡叶的分水岭分割算法

提问于
浏览
5

主要任务是消除叶子的复杂背景,并从MATLAB中的遮挡叶子图像中提取目标叶子 . 为了消除背景,我已经应用了K-means聚类算法 . 现在的主要任务是使用分水岭分割算法从遮挡的叶子中分割叶子 . 我无法为每一片叶子找到完美的片段 . 请帮我 . 我上传了样本图像和分水岭分段代码 .

ORIGINAL IMAGE
enter image description here

Image after eliminating background using K-Means clustering algorithm and watershed Segmentation superimposed on original image
enter image description here

我希望主中间叶片是单个片段,以便我可以提取它 .

我在下面给出了分水岭分段代码

function wateralgo(img)

F=imread(img);

F=im2double(F);

%Converting RGB image to Intensity Image
r=F(:,:,1);
g=F(:,:,2);
b=F(:,:,3);
I=(r+g+b)/3;
imshow(I);

%Applying Gradient
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
figure, imshow(gradmag,[]), title('Gradient magnitude (gradmag)');

L = watershed(gradmag);
Lrgb = label2rgb(L);
figure, imshow(Lrgb), title('Watershed transform of gradient magnitude (Lrgb)');

se = strel('disk',20);
Io = imopen(I, se);
figure, imshow(Io), title('Opening (Io)');
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I);
figure, imshow(Iobr), title('Opening-by-reconstruction (Iobr)');

Ioc = imclose(Io, se);
figure, imshow(Ioc), title('Opening-closing (Ioc)');

Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
figure, imshow(Iobrcbr), title('Opening-closing by reconstruction (Iobrcbr)');

fgm = imregionalmin(Iobrcbr);
figure, imshow(fgm), title('Regional maxima of opening-closing by reconstruction (fgm)');

I2 = I;
I2(fgm) = 255;
figure, imshow(I2), title('Regional maxima superimposed on original image (I2)');

se2 = strel(ones(7,7));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 20);
I3 = I;
I3(fgm4) = 255;
figure, imshow(I3), title('Modified regional maxima superimposed on original image (fgm4)');

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(gradmag, 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);
set(himage, 'AlphaData', 0.3);
title('Lrgb superimposed transparently on original image');
end

2 回答

  • 2

    我认为你应该尝试前景提取算法而不是一般的分割 . 一种这样的算法是GrabCut . 另一个有用的方法是在尝试提取前景对象之前在图像表示中实现某种程度的照明方差 . 一种方法是在_412784中工作 .

  • 0

    如果可以与用户进行任何交互,则使用GrabCut(如@Victor May所述)或更基本的interactive graph cut,您的细分会更好 .

    否则,自动分割很难完美地适用于各种图像 . 也许您可以尝试一些后处理,其中相邻区域基于相似性度量(或基于两个段之间的梯度的强度?)进行比较和合并 .

相关问题