M.
Interesting question.
Try something like this:
1. Fill all holes using imfill
filled = imfill(original, 'holes');
2. Identify filled pixels using logical operators:
holes = filled & ~original;
3. Use bwareaopen to eliminate connected components in the holes image
smaller than your threshold.
bigholes = bwareaopen(holes, 100);
4. Use logical operators to identify small holes:
smallholes = holes & ~bigholes;
5. Use logical operator to fill in identified small holes:
new = original | smallholes;
---
Steve Eddins
http://blogs.mathworks.com/steve/
I did this using,
new = ~bwareaopen(~original, 100);
The results are not quite the same - in contrast to imfill, this method will also
fill in holes occurring at the image boundary, which may or may not be
desirable.