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

Pei Dong peidong1030 at gmail.com
Fri May 6 05:40:44 EDT 2011


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!

Sincerely,
Pei DONG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110506/325e96b2/attachment.htm>


More information about the Insight-users mailing list