Hi Richard,<br><br>I don&#39;t know if you have time to help me, but I thought I would ask you anyways.<br>If you can&#39;t help me, that&#39;s ok.<br><br>As you suggested, I am trying to get a label map using itkBinaryImageToShapeLabelMapFilter, <br>

but I am getting zero label objects and I don&#39;t know why.<br><br>In my code below, I perform a connected threshold filter segmentation, then after some casting, I feed the segmentation<br>to an itkBinaryImageToLabelMapFilter, which is then fed to a itkLabelMapToLabelImageFilter, and finally to<br>

the itkBinaryImageToShapeLabelMapFilter.<br><br>Using the deprecated itkRelabelComponentImageFilter, I do get labeled objects, but I would like to get my code working using the itkBinaryImageToShapeLabelMapFilter.<br><br>

Can you see what I am doing wrong?<br><br>My output is below (the first four outputted lines are from the deprecated itkRelabelComponentImageFilter):<div class="im"><br><br>./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103 142 95 17100 17300<br>
</div><div class="im">
Number of pixel for object 0: 22129<br>Physical size for object 0: 23901<br>Number of pixel for object 1: 1<br>Physical size for object 1: 1.08004<br></div>labelMap-&gt;GetNumberOfLabelObjects() = 0<br><br><br>My code is below.<div>
<div><span id="q_125751924150cfb6_4" class="h4">- Show quoted text -</span></div><div class="h5"><br>

<br>/*<br>to run type:<br>./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103 142 95 17100 17300<br>*/<br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#ifdef __BORLANDC__<br>

#define ITK_LEAN_AND_MEAN<br>#endif<br><br><br>#include &quot;itkConnectedThresholdImageFilter.h&quot;<br><br>#include &quot;itkImage.h&quot;<br>#include &quot;itkCastImageFilter.h&quot;<br><br>#include &quot;itkCurvatureFlowImageFilter.h&quot;<br>

<br>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br><br>#include &quot;itkGDCMImageIO.h&quot;<br><br>#include &quot;itkVersion.h&quot;<br><br>#include &quot;itkOrientedImage.h&quot;<br>

#include &quot;itkMinimumMaximumImageFilter.h&quot;<br><br>#include &quot;itkGDCMImageIO.h&quot;<br>#include &quot;itkGDCMSeriesFileNames.h&quot;<br>#include &quot;itkNumericSeriesFileNames.h&quot;<br><br>#include &quot;itkImageSeriesReader.h&quot;<br>

#include &quot;itkImageSeriesWriter.h&quot;<br><br>#include &quot;itkResampleImageFilter.h&quot;<br>#include &quot;itkShiftScaleImageFilter.h&quot;<br><br>#include &quot;itkIdentityTransform.h&quot;<br>#include &quot;itkLinearInterpolateImageFunction.h&quot;<br>

<br>#include &lt;itksys/SystemTools.hxx&gt;<br><br>#include &quot;gdcm/src/gdcmFile.h&quot;<br>#include &quot;gdcm/src/gdcmUtil.h&quot;<br><br>#include &lt;string&gt;<br><br>//added per attribute_values.cxx<br>#include &quot;itkImageFileReader.h&quot;<br>

<br>#include &quot;itkShapeLabelObject.h&quot;<br><br></div></div><div class="im">#include &quot;itkLabelMap.h&quot;<br><br>#include &quot;itkBinaryImageToShapeLabelMapFilter.h&quot;<br></div>//end of added code<div class="im">
<br><br>//ADDED PER WEB PAGE<br>//<a href="http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html" target="_blank">http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html</a><br>
</div><div class="im">
#include &quot;itkConnectedComponentImageFilter.h&quot;<br>#include &quot;itkRelabelComponentImageFilter.h&quot;<br>//END OF ADDED CODE<br><br><br></div>//added per statistics_relabel.cxx<br>#include &quot;itkStatisticsRelabelImageFilter.h&quot;<br>

//end of added code<br><br>//added per label.cxx<br>#include &quot;itkLabelObject.h&quot;<br>#include &quot;itkLabelMap.h&quot;<br>#include &quot;itkBinaryImageToLabelMapFilter.h&quot;<br>#include &quot;itkLabelMapToLabelImageFilter.h&quot;<div>
<div><span id="q_125751924150cfb6_10" class="h4">- Show quoted text -</span></div><div class="h5"><br>
//end of added code<br><br>int main( int argc, char *argv[])<br>{<br>  if( argc &lt; 7 )<br>    {<br>    std::cerr &lt;&lt; &quot;Missing Parameters &quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];<br>

    std::cerr &lt;&lt; &quot; inputImage  outputImage seedX seedY seedZ lowerThreshold upperThreshold&quot; &lt;&lt; std::endl;<br><br>    return 1;<br>    }<br><br>  typedef   float           InternalPixelType;<br> <br>
  const     unsigned int    Dimension = 3;<br>
<br>  typedef itk::Image&lt; InternalPixelType, Dimension &gt;  InternalImageType;<br><br>  typedef signed short OutputPixelType;<br><br>  typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;<br>  typedef itk::Image&lt; float, Dimension &gt; OutputImageType2;<br>

  typedef itk::CastImageFilter&lt; InternalImageType, OutputImageType &gt;<br>    CastingFilterType;<br>  CastingFilterType::Pointer caster = CastingFilterType::New();<br>                       <br>  const    unsigned int    ImageDimension = 3;<br>

  typedef  signed short    PixelType;<br><br>  typedef itk::Image&lt; PixelType, ImageDimension &gt;  FixedImageType;<br>  typedef itk::Image&lt; float, ImageDimension &gt;  FloatImageType;<br><br>  typedef  itk::ImageFileReader&lt; FixedImageType &gt; ReaderType;<br>

  typedef  itk::ImageFileWriter&lt;  OutputImageType  &gt; WriterType;<br>  typedef  itk::ImageFileWriter&lt;  FloatImageType  &gt; WriterType2;<br><br>  ReaderType::Pointer reader = ReaderType::New();<br>  WriterType::Pointer writer = WriterType::New();<br>

  WriterType2::Pointer writer2 = WriterType2::New();<br><br>  typedef itk::GDCMImageIO           ImageIOTypefixed;<br>  ImageIOTypefixed::Pointer gdcmImageIOfixed = ImageIOTypefixed::New();<br>  reader-&gt;SetImageIO( gdcmImageIOfixed );<br>

<br>  typedef itk::GDCMImageIO           ImageIOTypefixed2;<br>  ImageIOTypefixed2::Pointer gdcmImageIOfixed2 = ImageIOTypefixed2::New();<br><br>  reader-&gt;SetFileName( argv[1] );<br>  <br>  reader-&gt;Update();<br><br>

  typedef itk::CurvatureFlowImageFilter&lt; InternalImageType, InternalImageType &gt;<br>    CurvatureFlowImageFilterType;<br> <br>  CurvatureFlowImageFilterType::Pointer smoothing =<br>                         CurvatureFlowImageFilterType::New();<br>

<br>  typedef itk::ConnectedThresholdImageFilter&lt; InternalImageType,<br>                                    InternalImageType &gt; ConnectedFilterType;<br><br>  ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();<br>

<br>  typedef signed short InputAPixelType;<br>  typedef float OutputBPixelType;<br><br>  typedef itk::Image&lt; InputAPixelType, 3 &gt; InputAImageType;<br>  typedef itk::Image&lt; OutputBPixelType, 3 &gt; OutputBImageType;<br>

<br>  typedef itk::CastImageFilter&lt; InputAImageType, OutputBImageType &gt; CastFilterType;<br><br>  CastFilterType::Pointer castFilter = CastFilterType::New();<br><br><br>  castFilter-&gt;SetInput( reader-&gt;GetOutput() );<br>

 <br><br>  connectedThreshold-&gt;SetInput( castFilter-&gt;GetOutput() );<br><br>  caster-&gt;SetInput( connectedThreshold-&gt;GetOutput() );<br><br><br>  smoothing-&gt;SetNumberOfIterations( 20 ); //was 5<br>  smoothing-&gt;SetTimeStep( 0.125 );<br>

 <br>  const InternalPixelType lowerThreshold = atof( argv[6] );<br>  const InternalPixelType upperThreshold = atof( argv[7] );<br> <br>  connectedThreshold-&gt;SetLower(  lowerThreshold  );<br>  connectedThreshold-&gt;SetUpper(  upperThreshold  );<br>

  <br>  connectedThreshold-&gt;SetReplaceValue( 255 );<br><br>  InternalImageType::IndexType  index;<br> <br>  index[0] = atoi( argv[3] );<br>  index[1] = atoi( argv[4] );<br> <br>  //added<br>  index[2] = atoi( argv[5] );<br>

<br></div></div><div class="im">  // Software Guide : BeginCodeSnippet<br>  connectedThreshold-&gt;SetSeed( index );<br> <br>  //obtain a 5 x 5 bounding region of seeds<br>  int ii, jj, kk;<br><br>  ii = index[0];<br>  jj = index[1];<br>
  kk = index[2];<br>
<br>  for (int i = ii; i &lt; ii + 5; i++)<br>    for (int j = jj; j &lt; jj + 5; j++)<br>      for (int k = kk; k &lt; kk + 5; k++)<br>    {<br>     <br>      index[0] = i;<br>      index[1] = j;<br>      index[2] = k;<br>

      connectedThreshold-&gt;AddSeed( index );<br>    }<br><br>  for (int i = ii; i &gt; ii - 5; i--)<br>    for (int j = jj; j &gt; jj - 5; j--)<br>      for (int k = kk; k &gt; kk - 5; k--)<br>    {<br>     <br>      index[0] = i;<br>

      index[1] = j;<br>      index[2] = k;<br>      connectedThreshold-&gt;AddSeed( index );<br>    }<br> <br></div><div class="im">  typedef itk::MetaDataDictionary DictionaryType;<br> <br>  DictionaryType inputdict = reader-&gt;GetMetaDataDictionary();<br>

 <br>  writer-&gt;SetMetaDataDictionary( inputdict );<br>   <br>  writer-&gt;SetFileName( argv[2] );<br><br>  <br><br></div>  //ADDED PER WEB PAGE: This deprecated code works<div class="im"><br>  //<a href="http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html" target="_blank">http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html</a><br>

  typedef itk::ConnectedComponentImageFilter &lt;OutputImageType, OutputImageType&gt;  LabelType2;<br>  typedef itk::RelabelComponentImageFilter &lt;OutputImageType, OutputImageType&gt; RelabelType;<br><br>  LabelType2::Pointer labeler = LabelType2::New();<br>

  RelabelType::Pointer relabeler = RelabelType::New();<br><br>  labeler-&gt;SetInput(caster-&gt;GetOutput());<br>  labeler-&gt;Update();<br><br>  relabeler-&gt;SetInput(labeler-&gt;GetOutput());<br>  relabeler-&gt;Update();<br>

<br>  for (unsigned int i=0; i&lt;relabeler-&gt;GetNumberOfObjects(); i++)<br>    {<br>        std::cout&lt;&lt;&quot;Number of pixel for object &quot;&lt;&lt;i&lt;&lt;&quot;: &quot;&lt;&lt;relabeler-&gt;GetSizeOfObjectsInPixels()[i]&lt;&lt;std::endl;<br>

<br>    std::cout&lt;&lt;&quot;Physical size for object &quot;&lt;&lt;i&lt;&lt;&quot;: &quot;&lt;&lt;relabeler-&gt;GetSizeOfObjectsInPhysicalUnits()[i]&lt;&lt;std::endl;<br>    }<br>  //END OF ADDED CODE<br><br></div>  /***************************************************************************/<br>

  //but the code below fails to label the binary image giving zero label objects<br>  /***************************************************************************/<br><br>  typedef itk::Image &lt; signed short, 3 &gt; IType;<br>

  <br>  typedef itk::LabelObject&lt; signed short, 3 &gt; LabelObjectTypeD;<br>  typedef itk::LabelMap&lt; LabelObjectTypeD &gt; LabelMapTypeD;<br>    <br>  typedef itk::BinaryImageToLabelMapFilter&lt; OutputImageType, LabelMapTypeD&gt; I2LType;<br>

  I2LType::Pointer i2l = I2LType::New();<br>  i2l-&gt;SetInput( caster-&gt;GetOutput() );<br>  i2l-&gt;SetFullyConnected( 255 );<br>  //i2l-&gt;SetForegroundValue( 100 );<br>  //i2l-&gt;SetBackgroundValue( 255 );<br>  //i2l-&gt;Update();<br>

  i2l-&gt;GetOutput()-&gt;PrintLabelObjects();<br>  typedef itk::LabelMapToLabelImageFilter&lt; LabelMapTypeD, IType&gt; L2IType;<br>  L2IType::Pointer l2i = L2IType::New();<br>  l2i-&gt;SetInput( i2l-&gt;GetOutput() );<br>

<br>  typedef signed short LabelType3;<br>  typedef itk::ShapeLabelObject&lt; LabelType3, 3 &gt; LabelObjectType2;<br>  typedef itk::LabelMap&lt; LabelObjectType2 &gt; LabelMapType2;<br><br>  typedef itk::BinaryImageToShapeLabelMapFilter&lt; IType, LabelMapType2 &gt; ConverterType;<div class="im">
<br>
  ConverterType::Pointer converter = ConverterType::New();<br></div>  converter-&gt;SetInput( l2i-&gt;GetOutput() );<br> <br>  <br>  LabelMapType2::Pointer labelMap = converter-&gt;GetOutput();<br><br>  std::cout &lt;&lt; &quot;labelMap-&gt;GetNumberOfLabelObjects() = &quot; &lt;&lt; labelMap-&gt;GetNumberOfLabelObjects() &lt;&lt; std::endl;<div class="im">
<br>
  <br>  writer-&gt;SetInput( caster-&gt;GetOutput() );<br><br>  try<br>    {<br>    writer-&gt;Update();<br>    }<br>  catch( itk::ExceptionObject &amp; excep )<br>    {<br>    std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>

    std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>    }<br><br></div>  return 0;<br>}<br><br>Thanks,<br><font color="#888888">john</font>