5

The main task is to eliminate the complicated background of a leaf and extract the targeted leaf from an occluded leaf image in MATLAB. To eliminate the background i have applied K-means clustering algo. Now the main task is to segment the leaf from an occluded leaf using watershed segmentation algorithm. I am not able to find the perfect segments for every single leaf. Please help me. I have uploaded the sample images and also watershed segmentation code.

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

I want the main middle leaf to be a single segment, so that i can extract it.

I have given the watershed segmentation code below

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
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • @Phonon Sorry the code is poorly indented but please help me the solution. – Rohit Kalaghatkar Apr 23 '12 at 16:59
  • which leaf are you trying to extract? – vini Apr 29 '12 at 08:07
  • Under what range of environmental conditions must your leaf segmentation algorithm perform? Do you have any control over the scene? Does it absolutely have to use a watershed algorithm? I am not sure the gradient information is strong enough to give you a robust solution. You probably want an algorithm or model that allows you to deploy stronger priors. The shape of the leaves is quite stereotyped, so perhaps look at a deformable model might be appropriate. If time is short, perhaps a heuristic approach based on region-growing might give you some quick results? – William Payne May 01 '12 at 19:44
  • @vini We are trying to extract the leaf that covers the maximum portion of the image. Which ever leaf that is in the center. And eliminate the rest other leaves. – Rohit Kalaghatkar May 02 '12 at 19:02
  • @WilliamPayne The Leaf segmentation algorithm should work for single leaf and occluded leaves with complicated background such as other leaves, soil, residues, stem, branches etc. After we apply the watershed segmentation algorithm we are not able to control the segmentation of the leaves properly. The leaf with a larger portion covering the image and also considering the leaf which is at the center must be extracted and the rest all must be eliminated. The algorithm needs refinement. Please suggest me else a different approach that works even better. – Rohit Kalaghatkar May 02 '12 at 19:10

2 Answers2

2

I think you should try a foreground extraction algorithm rather than a general segmentation. One such algorithm is GrabCut. Another thing that be helpful is to achieve some level of illumination variance in your image representation prior to trying to extract the foreground object. One way to do so is to work in the Chong color space.

nojka_kruva
  • 1,454
  • 1
  • 10
  • 23
0

If any interaction from the user is possible, your segmentation will be much better either with GrabCut (as mentioned by @Victor May) or the more basic interactive graph cut.

Otherwise, an automated segmentation is very difficult to perfect for a variety of images. Perhaps you could try some post-processing in which neighboring regions are compared and merged based on a similarity metric (or based on the strength of the gradient between the two segments?).

Noremac
  • 3,445
  • 5
  • 34
  • 62