[Insight-users] Fill holes in mask
Luis Ibanez
luis.ibanez at kitware.com
Thu, 22 Jan 2004 15:12:28 -0500
Hi Radhika,
How big are the holes ?
-------------------
Option (A):
You may want to try the GrayscaleFillholeImageFilter
http://www.itk.org/Insight/Doxygen/html/classitk_1_1GrayscaleFillholeImageFilter.html
If size is enough for characterizing the holes
you could use the connected components filter
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ConnectedComponentImageFilter.html
then collect the number of pixels per component
in order to identify the labeled regions that you
need to set ON in order to fill the holes.
------------------
Option (B):
You can use the
ThresholdConnectedImageFilter
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ConnectedThresholdImageFilter.html
Use the first pixel of the image as seed point
(assuming it is in the exterior of the shape)
and segment the "exterior" of your shape.
(this filter uses a flood fill iterator internally).
Then make a logical OR
http://www.itk.org/Insight/Doxygen/html/classitk_1_1OrImageFilter.html
between the exterior and the shape, which will give you
the negative map of the holes. If you negate this map
and do an OR between the map and the original shape, you
will end up with the shape without holes.
Image-->SegmentExterior--> OR ---> NOT ---> OR---> No holes
| ^ ^
| | |
+-----------------------+---------------- +
Note that we don't have a NOT image filter, you can
easily fabricate a NOR image filter out of the
existing OR filter just by changing line 56 from
return static_cast<TOutput>( A | B );
to
return static_cast<TOutput>( ~ ( A | B ) );
Actually, if you plan to do this very often,
you may get much better performance and less
memory consumption if you compose the entire
boolean operation in a single filter
A OR NOT( A OR B )
( A | ~ ( A | B )
where A is the pixel from the input image and
B is the pixel from the segmented exterior.
Regards,
Luis
--------------------------------
Radhika Sivaramakrishna wrote:
> Hi,
> I have a mask (binary image) with a few holes in the ON region. And I
> want to fill those holes. Is there
> already a procedure in ITK which does this automatically? Or can someone
> recommend a simple procedure to do this? Basically I think I need a
> flood fill operation but not sure how to use it in this context.
>
> Radhika
>