How to fill the unclosed shape?
5 views (last 30 days)
Show older comments
Kei Mukoyama
on 12 Dec 2022
Commented: Image Analyst
on 13 Dec 2022
I am now trying to create a mask to use in a machine learning annotation file.
In doing so, I would like to binarize the droplet image with a threshold value and then fill the inside of the droplet with imfill.
However, sometimes the boundary becomes an open curve due to some thinness in the boundary area.
In this case, what can I do to fill this area automatically?
Here is the code.
This is the first time to ask a question on matlab and I am not a fluent in English, so I apologize if there is any rudeness.
I_pp=double(rgb2gray(imread("img0.jpg")));
%I_bg=double(rgb2gray(imread("bg.jpg")));
diff=I_pp; %-I_bg;
min(min(diff))
result=((diff-min(min(diff)))/(max(max(diff))-min(min(diff))));
imshow(result)
level=graythresh(result);
BW=imbinarize(result,level);
BW(1:7, :)=1;
BW(end-7:end,:)=1;
BW= 1-BW;
BW2 = bwmorph(BW, 'bridge');
BW2=imclose(BW2,strel('disk',2));
imshow(BW2)
%%
I2 = imfill(BW2,'holes');
imshow(I2)
0 Comments
Accepted Answer
Image Analyst
on 12 Dec 2022
You can try imclose, but that's not your biggest problem. Your biggest problem is the non-uniformity of your illumination. It's most likely due to lens shading. You need to divide that out. First take a "blank" shot of nothing -- just the light background itself. Then divide your images with stuff in them by the background image. I attach a demo.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!