[Insight-users] LabelImageToShapeLabelMapFilter

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Mon Jun 16 15:07:55 EDT 2008


Le 16 juin 08 à 17:07, Irene Gonzálvez García a écrit :

> Dear Gaëtan ,
>
> Thanks a lot for your reply.I have been testing the example you told  
> m in a previous mail changing  
> "itkBinayImageToLabelCollectionImageFilter.h" by  
> "itkLabelImageToLabelCollectionImageFilter.h" because i am using  
> grayscale images.
>
> In the loop:
>
> for( int label=0; label<collection->GetNumberOfObjects(); label++ )
>       {
>
>           LabelObjectType::Pointer labelObject = collection- 
> >GetLabelObject( 83 );
>
>           std::cout << label << "\t" << labelObject- 
> >GetPhysicalSize() << "\t" << labelObject->GetCentroid() << std::endl;
>       }
> I found that some labels are not defined and I get this error:   
> Description: itk::ERROR: LabelCollectionImage(017D8F10): No label  
> object with label 1.  From label 2 to label 50 it works fine, but  
> then between 50 and 80 it occurs the same problem  (collection- 
> >GetNumberOfObjects()=85).

You get that message because your labels are not consecutive in your  
image. You can add a ShapeRelabelLabelMapFilter, and use the output of  
that filter to read the centroid position. You can also use the method  
GetNthLabelObject() instead of GetLabelObject() (but that last method  
can be very slow if you have many objects).

>
>
> Is there any possibility to select only the region which value is  
> maximum and calculate the centroid only for this region?

you can crop your image, mask it, etc, then run  
LabelImageToShapeLabelMapFilter.

> And the last question, when I get the centroid I would like to  
> create a new image which all pixels equal to zero except the  
> centroid pixel which value will be equal to 1. Is there anything  
> implemented?

simply write it to an empty image! Something like (not tested):

ImageType::Pointer img = ImageType::New();
img->SetRegions( collection->GetLargestPossibleRegion() );
img->Allocate();
img->Fill( 0 );
for( int label=0; label<collection->GetNumberOfObjects(); label++ )
   {
   LabelObjectType::Pointer labelObject = collection- 
 >GetNthLabelObject( label );
   img->SetPixel( collection- 
 >TransformPhysicalPointToIndex( labelObject->GetCentroid() ), 255 );
   }

Regards,

Gaëtan


>
>
> Best regards and thanks a lot for your help
> Irene
>
>
>
> Gaëtan Lehmann wrote:
>>
>> Le 16 juin 08 à 09:07, Irene Gonzálvez García a écrit :
>>
>> Hi Irene,
>>
>> A simple example with the same filter for a binary image is  
>> available at http://voxel.jouy.inra.fr/darcs/contrib-itk/binaryAttributeMorphology/attribute_values.cxx 
>>  , or in the source code on the insight journal.
>> Simply replace BinaryImageToShapeLabelMapFilter by  
>> LabelImageToShapeLabelMapFilter if your input image is a label image.
>>
>> 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.mandriva.org
http://www.itk.org  http://www.clavier-dvorak.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080616/b05790e5/attachment.pgp>


More information about the Insight-users mailing list