1

I want to get only leaf from an image. The background is a normal white paper(A4) and there is some shadow.

I apply some method (structure element,edge detection using filter) but I cannot find the general way which can apply all the image.

these are examples. ex1

ex2

Are there better methods for this problem??

thank you

another example. ex3

and the result I got is ex3_result

By using

hsv_I = rgb2hsv(I);
Is = hsv_I(:,:,2);
Is_d = imdilate(Is,strel('diamond',4));
Is_e = imerode(Is,strel('diamond',2));
Is_de = imerode(Is_d,strel('disk',2));
Is_def = imfill(Is_de,'holes');
Is_defe = imerode(Is_def,strel('disk',5));

Then Is_defe is a mask to segment enter image description here

But the method that i did is very specific. I cannot use this in general.

CSchulz
  • 10,882
  • 11
  • 60
  • 114
BOSS
  • 43
  • 7

1 Answers1

0

If you have the Image Processing Toolbox, you could do as follows:

The code below first estimates the threshold with the function graythresh, thresholds the image and fills holes with the imfill function. Suppose I is a cell containing your RGB images:

for k=1:length(I)
    t=graythresh(rgb2gray(I{k}));
    BW{k}=imfill(~im2bw(I{k}, t), 'holes');
    subplot(length(I),1,k), imshow(BW{k});
end

enter image description here

Cape Code
  • 3,584
  • 3
  • 24
  • 45
  • I contains 3 pictures and k is number of picture ,isn't it ? – BOSS Feb 07 '14 at 16:54
  • thank for your idea,but i think that your result includes the shadow which i does not need. – BOSS Feb 07 '14 at 16:58
  • @BOSS yes, `I` is a cell with 3 images in this case, hence `k` loops from 1 to 3. The loop is not strictly necessary for you, it's just to automate the process. – Cape Code Feb 07 '14 at 17:00
  • @BOSS than I would suggest to use only the green channel. Replace the first line of the loop with: `t=graythresh(I{k}(:,:,2));` – Cape Code Feb 07 '14 at 17:01