Hi,<br><br>Sorry for repeating my message but I had to clip my message to a shorter length because it originally bounced from the insight-users mailing list.<br><br>Thanks,<br>john<br><br><div class="gmail_quote">On Fri, Dec 11, 2009 at 1:58 PM, John Drozd <span dir="ltr">&lt;<a href="mailto:john.drozd@gmail.com">john.drozd@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello Luis, Richard and Bonjour Gaetan, <br><br>Thank you all for helping me.  My code works now giving me the correct output:<br>
<br>[jdrozd@trumpet ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$ ./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103 142 95 17100 17300<br>
labelMap-&gt;GetNumberOfLabelObjects() = 1<br>1       23901.3 [294.881, 123.841, -97.2387]<br><br> Below is my code to complete the communication thread (and thanks again):<div><div></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><div class="im">
//end of added code<br><br>//added per label.cxx<br></div>#include &quot;itkLabelObject.h&quot;<br>#include &quot;itkLabelMap.h&quot;<br>#include &quot;itkBinaryImageToLabelMapFilter.h&quot;<br>#include &quot;itkLabelMapToLabelImageFilter.h&quot;<br>

//end of added code<br><br>#include &quot;itkSimpleFilterWatcher.h&quot;<div class="im"><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></div>  typedef   unsigned char          BinaryPixelType;<div class="im"><br><br>  const     unsigned int    Dimension = 3;<br><br></div>  typedef itk::Image&lt; BinaryPixelType, Dimension &gt;  BinaryImageType;<br>  <br>
<br>  typedef signed short InputPixelType;<br>
<br>  typedef itk::Image&lt; InputPixelType, Dimension &gt; InputImageType;<br>  typedef unsigned char LabelType;<br>  const unsigned int dim = 3;<br>  typedef itk::ShapeLabelObject&lt; LabelType, dim &gt; LabelObjectType;<div class="im">
<br>
  typedef itk::LabelMap&lt; LabelObjectType &gt; LabelMapType;<br></div>  typedef itk::BinaryImageToShapeLabelMapFilter&lt; BinaryImageType, LabelMapType&gt; ConverterType;<div class="im"><br><br>  ConverterType::Pointer converter = ConverterType::New();<br>

<br></div>  typedef  itk::ImageFileReader&lt; InputImageType &gt; ReaderType;<br>  typedef  itk::ImageFileWriter&lt;  BinaryImageType  &gt; WriterType;<div class="im"><br>  <br>  ReaderType::Pointer reader = ReaderType::New();<br>
  WriterType::Pointer writer = WriterType::New();<br>
 <br></div><div class="im">  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></div>  typedef itk::ConnectedThresholdImageFilter&lt; InputImageType,<br>

                                    BinaryImageType &gt; ConnectedFilterType;<div class="im"><br><br>  ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();<br>  <br></div>  connectedThreshold-&gt;SetInput( reader-&gt;GetOutput() );<br>

<br>  const InputPixelType lowerThreshold = atof( argv[6] );<br>  const InputPixelType upperThreshold = atof( argv[7] );<div class="im"><br><br>  connectedThreshold-&gt;SetLower(  lowerThreshold  );<br>  connectedThreshold-&gt;SetUpper(  upperThreshold  );<br>

  <br>  connectedThreshold-&gt;SetReplaceValue( 255 );<br><br></div>  BinaryImageType::IndexType  index;<div class="im"><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 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></div>  connectedThreshold-&gt;Update();<br><br>  converter-&gt;SetInput( connectedThreshold-&gt;GetOutput() );<br>
<br>  converter-&gt;SetFullyConnected( true );<br>
  <br>  converter-&gt;SetInputForegroundValue( 255 );<br><br>  converter-&gt;SetOutputBackgroundValue( 0 );<br><br>  converter-&gt;Update();<br><br>  LabelMapType::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>  for( unsigned int label=1; label&lt;=labelMap-&gt;GetNumberOfLabelObjects(); label++ )<br>    {<br>    // we don&#39;t need a SmartPointer of the label object here, because the reference is kept in<br>    // in the label map.<br>

    const LabelObjectType * labelObject = labelMap-&gt;GetLabelObject( label );<br>    std::cout &lt;&lt; label &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject-&gt;GetPhysicalSize() &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject-&gt;GetCentroid() &lt;&lt; std::endl;<br>

    }<br>  <br></div>  typedef itk::LabelMapToLabelImageFilter&lt; LabelMapType, BinaryImageType &gt; L2IType;<div class="im"><br><br>  L2IType::Pointer l2i = L2IType::New();<br>  <br></div>  l2i-&gt;SetInput( converter-&gt;GetOutput() );<br>
<br>  writer-&gt;SetInput( l2i-&gt;GetOutput() );<div class="im"><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;<div><div></div><div class="h5"><br>}<br><br><br><br><br></div></div></blockquote></div><br>