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

2019-08-05 05:10发布

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.

1条回答
ら.Afraid
2楼-- · 2019-08-05 05:39

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

查看更多
登录 后发表回答