How to fill holes in binary image

22 ビュー (過去 30 日間)
LORENZO GRILLI
LORENZO GRILLI 2019 年 6 月 13 日
コメント済み: Image Analyst 2020 年 4 月 9 日
Hello buddy,
I know that some posts already exist regarding this problem, but I'm still struggling in a similar issue. I have a .avi file from which I extract, frame by frame, the animal pupil, but are present in the image these three reflecting blobs of light that makes the binary conversion weird. I don't know how to get rid off them.
Someone, could help me, pls?
Ps: just to let you know I had this code within a for loop
image_frame = read (video,cnt);
piel_1 = ~im2bw(image_frame,0.15);
piel_2 = bwmorph(piel_1,'open');
piel_3 = bwmorph(piel_2,'close');
piel_4 = bwareaopen(piel_3,2000);
piel = imfill(piel_4,'holes');

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 13 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 13 日
"How to fill holes in binary image"
J = imerode( binary_image_name , SE ) ;
% chosse the structuring elment as per your requiremnet
For detail see here
  2 件のコメント
LORENZO GRILLI
LORENZO GRILLI 2019 年 6 月 14 日
編集済み: LORENZO GRILLI 2019 年 6 月 14 日
Thanks for your answer, but I'm not able to manage the issue with the function that you suggested, I'm naive to Matlab and in general to coding, so sorry if I have not understood your suggestion.
Maybe the problem resides at the edge of the missing part because the function imfill replace the holes surrounded by 1 and I do not have enough 1 in the missing part.
Now, I have extracted the three reflecting blobs, and I'm trying to add them to the matrix of my pupil but seems not affecting the image. Maybe something is wrong in my code, please could you help me?
mask = imbinarize(image_frame);
for k = 1:length(piel)
if piel(k,:) + mask(k,:) > 1
piel(k,:) = piel(k,:);
end
if piel(k,:) + mask(k,:)==0
piel(k,:) = piel(k,:);
end
if piel(k,:) + mask(k,:)==1
piel(k,:)=piel(k,:)+mask(k,:);
end
end
darova
darova 2019 年 6 月 15 日
What does this part suppose to mean?
piel(k,:) = piel(k,:);

サインインしてコメントする。


Image Analyst
Image Analyst 2019 年 6 月 15 日
To fill holes in a binary image:
bw = imfill(bw, 'holes');
  2 件のコメント
Muhammad Zeeshan Ahmed Khan
Muhammad Zeeshan Ahmed Khan 2020 年 4 月 9 日
This is not filling the hole in a binary image please guide
Image Analyst
Image Analyst 2020 年 4 月 9 日
OK, sure. Where is your image? You forgot to attach it. ?‍♂️
Are you sure your image is just larger than the display and there is a small path to the background that gets subsampled away when it goes to display it so that you don't see that path to the background and you think it's a hole when it's really not? So I can check for that you must attach your binary image in a PNG format file or a .mat file, NOT as a JPG image.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by