How to fill the unclosed shape?
4 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1228057/image.jpeg)
However, sometimes the boundary becomes an open curve due to some thinness in the boundary area.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1228062/image.jpeg)
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 个评论
采纳的回答
Image Analyst
2022-12-12
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!