segment object(leaf) which is on the white paper u

2019-08-05 05:44发布

问题:

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.

Are there better methods for this problem??

thank you

another example.

and the result I got is

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

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

回答1:

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