Select largest object in an image

后端 未结 2 1856
不思量自难忘°
不思量自难忘° 2020-12-03 16:16

I am trying to find the the largest object in an image and remove any other objects in the image that are smaller than it.

This is what I have but I cannot get it to

2条回答
  •  伪装坚强ぢ
    2020-12-03 16:31

    If you would like to continue with the bwlabel approach, you may use this -

    Code

    BW = im2bw(imread('coins.png')); %%// Coins photo from MATLAB Library
    
    [L, num] = bwlabel(BW, 8);
    count_pixels_per_obj = sum(bsxfun(@eq,L(:),1:num));
    [~,ind] = max(count_pixels_per_obj);
    biggest_blob = (L==ind);
    
    %%// Display the images
    figure,
    subplot(211),imshow(BW)
    subplot(212),imshow(biggest_blob)
    

    Output

    enter image description here

提交回复
热议问题