<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&#39;t work. I got an error message at the run time. It looks from the debugger that the line </div>
<div> </div><div>labelerAttribute-&gt;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 &quot;itkAttributeImageLabelObject.h&quot;</p><p>const      unsigned int    Dimension = 2;<br>typedef  unsigned char LabelPixelType;<br>typedef  itk::Image&lt; LabelPixelType, Dimension &gt;  LabelImageType;<br>
typedef  unsigned char                           OutputPixelType;<br> typedef  itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;<br>typedef   itk::ImageFileReader&lt; OutputImageType &gt; ReaderType;<br>typedef   itk::ImageFileWriter&lt;  OutputImageType  &gt; WriterType;<br>
typedef  itk::AttributeImageLabelObject&lt; LabelPixelType, Dimension, OutputImageType &gt; LabelObjectAttributeType;<br> typedef  itk::LabelMap&lt;LabelObjectAttributeType&gt; LabelMapAttributeType;<br>typedef  itk::BinaryImageToShapeLabelMapFilter <br>
   &lt;OutputImageType, LabelMapAttributeType&gt;  LabelMapperAttributeType;<br>typedef  itk::LabelMapToLabelImageFilter&lt;LabelMapAttributeType, OutputImageType&gt; LabelMapToLabelImageFilterType;<br> typedef  itk::BoundingBoxImageLabelMapFilter&lt;LabelMapAttributeType&gt; BBILabelMapFilter;<br>
typedef   itk::ImageFileWriter&lt;  OutputImageType  &gt; WriterType;</p><p>ReaderType::Pointer reader = ReaderType::New();</p><p>reader-&gt;SetFileName( argv[1] );<br> <br>LabelMapperAttributeType::Pointer labelerAttribute = LabelMapperAttributeType::New();</p>
<div><br>labelerAttribute-&gt;SetInput( reader-&gt;GetOutput() );<br>labelerAttribute-&gt;SetComputePerimeter( false ); <br> labelerAttribute-&gt;SetOutputBackgroundValue(0); <br>labelerAttribute-&gt;Update();</div><div> </div>
<div> </div><div>//select the item with the label 1</div><p>const LabelObjectAttributeType* labelObjectAttribute = toBBILabelMap-&gt;GetOutput()-&gt;GetLabelObject(1);</p><p>BBILabelMapFilter::Pointer toBBILabelMap =  BBILabelMapFilter::New();<br>
toBBILabelMap-&gt;SetInput(labelMapAttribute);<br>toBBILabelMap-&gt;Update();</p><p><br>Thanks.<br>Best <br><span><font color="#888888">EM </font></span></p></div>