Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

imfill(image,'holes',sizeHoles)

620 views
Skip to first unread message

Mario

unread,
Jul 23, 2008, 11:01:02 PM7/23/08
to
Hi.
Is there any way to select the holes I want to fill?
I'd like to fill just the holes smaller than a certain size
(say 100 pixels), so I was wondering if there is a way to do
that. Possibly without using imdilate and imerode (because
using these commands it can happen that i fill holes that i
want to keep).
Thanks for your help!

M.

Steve Eddins

unread,
Jul 24, 2008, 8:29:07 AM7/24/08
to

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/

Pete

unread,
Aug 30, 2008, 7:58:02 AM8/30/08
to
Hi,

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.

0 new messages