<div dir="ltr"><div>Hi all, <br>I am trying to use itk to select a component from a binary image. The binary image contains several items and I want to separate them in different images.<br>   <br>I used the code below but it doesn't work. I got an error message at the run time. It looks from the debugger that the line </div>
<div> </div><div>labelerAttribute->Update() </div><div> </div><div>causes the error. I gave a valid file as input and  checked that ITK reads correctly this file.  I would appreciate your help to fix this! </div><p><br>
 #include "itkAttributeImageLabelObject.h"</p><p>const      unsigned int    Dimension = 2;<br>typedef  unsigned char LabelPixelType;<br>typedef  itk::Image< LabelPixelType, Dimension >  LabelImageType;<br>
typedef  unsigned char                           OutputPixelType;<br> typedef  itk::Image< OutputPixelType, Dimension > OutputImageType;<br>typedef   itk::ImageFileReader< OutputImageType > ReaderType;<br>typedef   itk::ImageFileWriter<  OutputImageType  > WriterType;<br>
typedef  itk::AttributeImageLabelObject< LabelPixelType, Dimension, OutputImageType > LabelObjectAttributeType;<br> typedef  itk::LabelMap<LabelObjectAttributeType> LabelMapAttributeType;<br>typedef  itk::BinaryImageToShapeLabelMapFilter <br>
   <OutputImageType, LabelMapAttributeType>  LabelMapperAttributeType;<br>typedef  itk::LabelMapToLabelImageFilter<LabelMapAttributeType, OutputImageType> LabelMapToLabelImageFilterType;<br> typedef  itk::BoundingBoxImageLabelMapFilter<LabelMapAttributeType> BBILabelMapFilter;<br>
typedef   itk::ImageFileWriter<  OutputImageType  > WriterType;</p><p>ReaderType::Pointer reader = ReaderType::New();</p><p>reader->SetFileName( argv[1] );<br> <br>LabelMapperAttributeType::Pointer labelerAttribute = LabelMapperAttributeType::New();</p>
<div><br>labelerAttribute->SetInput( reader->GetOutput() );<br>labelerAttribute->SetComputePerimeter( false ); <br> labelerAttribute->SetOutputBackgroundValue(0); <br>labelerAttribute->Update();</div><div> </div>
<div> </div><div>//select the item with the label 1</div><p>const LabelObjectAttributeType* labelObjectAttribute = toBBILabelMap->GetOutput()->GetLabelObject(1);</p><p>BBILabelMapFilter::Pointer toBBILabelMap =  BBILabelMapFilter::New();<br>
toBBILabelMap->SetInput(labelMapAttribute);<br>toBBILabelMap->Update();</p><p><br>Thanks.<br>Best <br><span><font color="#888888">EM </font></span></p></div>