[Insight-users] itkBinaryImageToShapeLabelMapFilter

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Wed Dec 9 16:01:34 EST 2009


Hi,

Le 9 déc. 09 à 21:03, John Drozd a écrit :

> Hi Richard,
>
> I don't know if you have time to help me, but I thought I would ask  
> you anyways.
> If you can't help me, that's ok.
>
> As you suggested, I am trying to get a label map using  
> itkBinaryImageToShapeLabelMapFilter,
> but I am getting zero label objects and I don't know why.
>
> In my code below, I perform a connected threshold filter  
> segmentation, then after some casting, I feed the segmentation
> to an itkBinaryImageToLabelMapFilter, which is then fed to a  
> itkLabelMapToLabelImageFilter, and finally to
> the itkBinaryImageToShapeLabelMapFilter.

This is really _not_ the typical use of those filters. If your  
segmented image is a binary image, BinaryImageToShapeLabelMapFilter  
alone should be enough; if it is a label image,  
LabelImageToShapeLabelMapFilter alone should be enough.

<snip>

>
>   //ADDED PER WEB PAGE: This deprecated code works
>
>   //http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html
>   typedef itk::ConnectedComponentImageFilter <OutputImageType,  
> OutputImageType>  LabelType2;
>   typedef itk::RelabelComponentImageFilter <OutputImageType,  
> OutputImageType> RelabelType;
>
>   LabelType2::Pointer labeler = LabelType2::New();
>   RelabelType::Pointer relabeler = RelabelType::New();
>
>   labeler->SetInput(caster->GetOutput());
>   labeler->Update();
>
>   relabeler->SetInput(labeler->GetOutput());
>   relabeler->Update();
>
>   for (unsigned int i=0; i<relabeler->GetNumberOfObjects(); i++)
>     {
>         std::cout<<"Number of pixel for object "<<i<<": "<<relabeler- 
> >GetSizeOfObjectsInPixels()[i]<<std::endl;
>
>     std::cout<<"Physical size for object "<<i<<": "<<relabeler- 
> >GetSizeOfObjectsInPhysicalUnits()[i]<<std::endl;
>     }
>   //END OF ADDED CODE
>
>   / 
> ***************************************************************************/
>   //but the code below fails to label the binary image giving zero  
> label objects
>   / 
> ***************************************************************************/
>
>   typedef itk::Image < signed short, 3 > IType;
>
>   typedef itk::LabelObject< signed short, 3 > LabelObjectTypeD;
>   typedef itk::LabelMap< LabelObjectTypeD > LabelMapTypeD;
>
>   typedef itk::BinaryImageToLabelMapFilter< OutputImageType,  
> LabelMapTypeD> I2LType;
>   I2LType::Pointer i2l = I2LType::New();
>   i2l->SetInput( caster->GetOutput() );
>   i2l->SetFullyConnected( 255 );

SetFullyConnected() takes a boolean as parameter, so

   i2l->SetFullyConnected( true );

may be a better practice. Please note also that the connectivity won't  
usually have an important effect on the result - setting it to true or  
false can't explain that you have no object at the end.

>   //i2l->SetForegroundValue( 100 );

This parameter is quite likely to be the important missing one, but is  
now set with

   SetInputForegroundValue( value )

Unlike the ConnectedComponentImageFilter, which defines the pixels  
within the objects as the pixels with a value not equal to 0,  
BinaryImageTo*LabelMapFilter defines the pixels within the object as  
the ones with a value equal to InputForegroundValue. I didn't checked  
the rest of the code, but with the pixel types used and the cast done,  
the default value is unlikely to be the right one.

>   //i2l->SetBackgroundValue( 255 );

this is commented, so that's not a problem, but you usually want a  
background value of 0 in the output LabelMap.

>   //i2l->Update();
>   i2l->GetOutput()->PrintLabelObjects();

This won't print any object if Update() has not been called before -  
you should uncomment the previous line.

Regards,

Gaëtan


-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr  http://www.itk.org
http://www.mandriva.org  http://www.bepo.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091209/3e5f866f/attachment.pgp>


More information about the Insight-users mailing list