MATLAB: How can i remove the white object from binary image

binary imageimage processing

I have a image with my needed object (green) and the noise (white). I want to delete the noise but have no idea for that. anyone can help

Best Answer

You can use regionprops to compute circularity, eccentricity, or use major axis and minor axis lengths to find required shape of blob.
I used major and minor axis:
img = logical(rgb2gray(imread('green.png')));
dilate_img = imdilate(img,strel('disk',2));
BW = bwlabel(dilate_img);
blobprops = regionprops(BW, 'MajorAxisLength','MinorAxisLength', 'Eccentricity');
allMajorAxisLength = [blobprops.MajorAxisLength];
allMinorAxisLength = [blobprops.MinorAxisLength];
allEccentricity = [blobprops.Eccentricity];
MajorbyMinor = allMajorAxisLength./allMinorAxisLength;
[B,I] = sort(MajorbyMinor);
BW2 = ismember(BW,I(1));
% Using eccentricity
% [B,I] = sort(allEccentricity); % eccentricity = 0: circle, = 1: line
% BW2 = ismember(BW,I(1));
subplot(131), imshow(img), title('Original');
subplot(132), imshow(BW), title('Label');
subplot(133), imshow(BW2), title('desired');