[ITK Community] [Insight-developers] Detect holes in binary images

Padfield, Dirk R (GE Global Research) padfield at research.ge.com
Fri Feb 7 12:38:27 EST 2014


Hi Guys,

Another simple approach is to just fill the holes and then subtract the original image from this filled image.  You can then label the resulting holes and measure statistics on them if you like.  Below is example code using SimpleITK.  Does this work for you?

Dirk


import SimpleITK as sitk
import numpy as np
from matplotlib.pyplot import *

array = np.array([[0,0,0,0,0,0,0,0],
[0,0,1,1,1,1,0,0],
[0,0,1,0,0,1,0,0],
[0,0,1,1,1,1,0,0],
[0,0,0,0,0,0,0,0]],'uint8')

inImage = sitk.GetImageFromArray(array);
filledImage = sitk.BinaryFillhole(inImage);
holeImage = filledImage - inImage
figure; imshow(sitk.GetArrayFromImage(holeImage)); show()



> Hi Brad,
> I tried with a toy image, I get labels for the shapes and labels for
> the holes inside these shapes. How to select the labels that
> correspond only to the holes? Also, taken the image or the invert of
> the image didn't change the output of the connected components? Here's
> one of the toy image that I used with the output of the connected
> components.
> 
> A =
> 00000000
> 00111100
> 00100100
> 00111100
> 00000000
> 
> output =
> 00000000
> 00111100
> 00122100
> 00111100
> 00000000
> 
> 
> Thank you.
> 
> Best,
> 
> 
> On Fri, Feb 7, 2014 at 8:00 AM, Bradley Lowekamp <blowekamp at mail.nih.gov> wrote:
>> Hello,
>> 
>> Hole come in a variety of shapes sized and definitions.  Depending on there exact morphological shape that you are interested in it may very how to detect them. ITK has a large number of morphological filter which can be used to.
>> 
>> At a basic level to get you started, I'd suggest inverting you binary image, with the NotImageFilter. Then running ConnectedComponentImageFilter, to give each isolated hole a unique label. Then the LabelStatisticsImageFilter to get basic size and shape information.
>> 
>> If additional morphological filtering is needed I'd recommend try out SimpleITK in Python, so that a large number of filters can be played with to get the desired filtered effect.
>> 
>> Hope that helps,
>> Brad
>> 
>> On Feb 7, 2014, at 7:32 AM, elhadj meljane <elhadj.meljane at gmail.com> wrote:
>> 
>>> Hi all,
>>> I would appreciate suggestions to detect holes in binary images. The
>>> holes are of different sizes (small medium).  I am not looking to fill
>>> these holes but just to detect their locations.
>>> 
>>> Thank you.
>>> 
>>> Best,
>>> Elhadj
>>> _______________________________________________
>>> Powered by www.kitware.com
>>> 
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>> 
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://kitware.com/products/protraining.php
>>> 
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>> 
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-developers
>> 
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers



More information about the Community mailing list