How to fill a large hole?
Mostra commenti meno recenti
The imfill function doesn't fill the large hole. How can I fill it?
Or, more generally:
How can I separate the image from the background?
Using a very large 'disk' might work to fill the hole, but it would also make the subject too large.
Any suggestions?
Thank you!
I = imread("sample_image.png");
BW = imbinarize(I);
se = strel('disk',40);
closeBW = imclose(BW,se);
BW2 = imfill(closeBW,'holes');
figure
imshowpair(I,BW2,'montage')

Risposta accettata
Più risposte (1)
Walter Roberson
il 13 Gen 2025
Modificato: Walter Roberson
il 13 Gen 2025
The provided JPEG image is RGB, not gray.
The provided JPEG image has a white border around it.
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1823171/image.jpeg');
I = rgb2gray(I);
I = imclearborder(I);
BW = imbinarize(I);
se = strel('disk',40);
closeBW = imclose(BW,se);
BW2 = imfill(closeBW,'holes');
imshow(BW2)
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



