How to fill the unclosed shape?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kei Mukoyama
le 12 Déc 2022
Commenté : Image Analyst
le 13 Déc 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 commentaires
Réponse acceptée
Image Analyst
le 12 Déc 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.
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!