[Insight-users] How to assign a new label value to Label objects in a LabelMap

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Tue May 10 05:04:25 EDT 2011


Le 6 mai 11 à 11:40, Pei Dong a écrit :

> Hello,
>
> It concerned to itk::LabelMap, itk::ShapeLabelObject,  
> itk::LabelMapToLabelImageFilter
>
> I have a question about how to change the label value of label  
> object in a label map and convert into an new label image.
>
> I try to assign each label object in a label map with a new label  
> value by using "labelObj->SetLabel(new_value)". However, after I  
> converted the label Map into an label image using  
> "itk::LabelMapToLabelImageFilter" , the label value of the coverted  
> image doesn't change to new_value.
>
> The code looks like below:
> // read and convert image into a labelmap
> ...
> LabelMapType::Pointer labelMap = converter->GetOutput();
> LabelMapType::LabelObjectContainerType::iterator it;
> LabelMapType::LabelObjectContainerType & labelObjectContainer =  
> labelMap->GetLabelObjectContainer();
> for( it = labelObjectContainer.begin(),it !=  
> labelObjectContainer.end(); it++)
> {
>    ...
>    new_value = image2->GetPixel(index);
> //!!!try to change the label here!!!
>    it->second->SetLabel(new_value);
> }
>
> typedef itk::LabelMapToLabelImageFilter< LabelMapType,  
> LacunaDistanceImageType > M2IFilterType;
>
>   M2IFilterType::Pointer m2i = M2IFilterType::New();
>      m2i->SetInput(labelMap);//The labels remain the same?!
>      m2i->Update();
> //save image...
>      ...
>      writer->GetInput(m2i->GetOutput());
>
> Thanks in advance!


Hi,

The Label is a special attribute. It can't be changed that way.
The Label is used as the key of a std::map< LabelType,  
LabelObjectPointer>. The Label has to be changed there also.

The best way to change the label is with ChangeLabelLabelMapFilter.  
With that filter, you can specify a list of pair of old-new label.

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/20110510/374ce50a/attachment.pgp>


More information about the Insight-users mailing list