I am using MATLAB to analyze some features on a grayscale image through thresholding. I have the following code snippet which is able to identify most of the features of interest (an example is attached). However, imfill is unable to fully fill larger features and thus creates an issue later on when I try to measure feature characteristics. I tried using a higher connectivity value like 8 but that did not help. Any ideas on how to get around this issue is greatly appreciated.
filename = 'test.tif';
I = imread(filename);
bw = imbinarize(I,'adaptive','ForegroundPolarity','dark','Sensitivity',0.7);
bw = bwareaopen(bw,20);
se = strel('disk',3);
bw = imclose(bw,se);
bw = imfill(bw,'holes');
imshowpair(bw,I,'montage');
t = title('bw vs. original');