how can i remove the white object from binary image

조회 수: 3 (최근 30일)
R G
R G 2018년 4월 13일
편집: Image Analyst 2018년 4월 18일
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

채택된 답변

Gopichandh Danala
Gopichandh Danala 2018년 4월 13일
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));
figure,
subplot(131), imshow(img), title('Original');
subplot(132), imshow(BW), title('Label');
subplot(133), imshow(BW2), title('desired');
  댓글 수: 2
R G
R G 2018년 4월 14일
편집: R G 2018년 4월 14일
what is the meaning of imdilate step
dilate_img = imdilate(img,strel('disk',2));
I mean why you need to make the line more fat since the object is fat and short, the noise is thin and long. Can we use that characteristic as an advantage.
and this line is kinda tricky.
BW2 = ismember(BW,I(1));
Since every object have a different "MajorbyMinor " value and I don't know how many object that I need. That code make us always can get only one object. I think a threshold of "MajorbyMinor " or "eccentricity" will work better.
that is my first idea for this problem but I don't know how to make it possible in code. I am not quite sure about that, can you explain more about your idea.
Gopichandh Danala
Gopichandh Danala 2018년 4월 17일
The answer is always based on your question. You specifically asked for the green object in your image, so I answered accordingly. For imdilate, ismember, check the documentation. The reason to use dilate in this case is to connect the objects on the right to make it as one. so, it's easy to identify it as not being a round object. To make this more generic to identify multiple regions which satisfy a certain threshold condition.
MajorbyMinor = allMajorAxisLength./allMinorAxisLength;
thresh_value = 4; % set a threshold value
indxs = MajorbyMinor < thresh_value;
% [B,I] = sort(MajorbyMinor);
BW2 = ismember(BW,find(indxs));
It all depends on your requirement. i.e. the shape, size of the object. Adjust the threshold value to meet your requirement.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 4월 15일
You didn’t say what was unique about the object but it looks like it might be the size of the bounding box. So why don’t you compute that with regionprops()?
  댓글 수: 2
R G
R G 2018년 4월 15일
my bad, I am kinda amateur about this. I think the object is short and fat. the noise is thin and long. So it may concern to major axis and minor axis. That is all I can say.
how do you see it concern with the bounding box. Can you explain more detail?
Image Analyst
Image Analyst 2018년 4월 18일
편집: Image Analyst 2018년 4월 18일
Compute the bounding box.
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'BoundingBox');
Then decide which ones to keep, like if the width to height ratio is between 0.5 and 3, or whatever.
indexesToKeep = false(1, length(props));
for k = 1 : length(props)
width = props(k).BoundingBox(3);
height = props(k).BoundingBox(4);
if width/height > 0.5 || width/height < 3
% It's a fairly square box, so keep it.
indexesToKeep(k) = true;
end
end
% Extract just acceptable blobs
indexesToKeep = find(indexesToKeep);
binaryImage2 = ismember(labeledImage, indexesToKeep);
imshow(binaryImage2);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by