Hi again,<br><br>I reverted to using an antiquated &quot;RelabelComponentImageFilter.h&quot; header to get the volume of the ventricles, <i><b>but is there a way to get the physical size using a non-antiquated currently used header?</b></i><br>
<br>I used:<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">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>This gave me a ventricle size of <br>
Number of pixel for object 0: 22129<br>
Physical size for object 0: 23901<br>
<br>When I created a label map using the gui in 3DSlicer, I got a similar size but not exactly the same size:<br>Number of pixel for object 0: 22130<br>

Physical size for object 0: 23901.284681<br><br>Below is the updated code:<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>//#include &quot;itkStatisticsLabelObject.h&quot;<br><br>#include &quot;itkLabelMap.h&quot;<br>
<br>#include &quot;itkBinaryImageToShapeLabelMapFilter.h&quot;<br>//#include &quot;itkBinaryImageToStatisticsLabelMapFilter.h&quot;<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">http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html</a><br>
#include &quot;itkConnectedComponentImageFilter.h&quot;<br>#include &quot;itkRelabelComponentImageFilter.h&quot;<br>//END OF ADDED CODE<br><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>  std::cout &lt;&lt; index &lt;&lt; std::endl;<br><br>  // 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>  connectedThreshold-&gt;Print(std::cout,17100);<br> <br>  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>  //added per attribute_values.cxx<br><br>  // define the object type. Here the ShapeLabelObject type<br>  // is chosen in order to read some attribute related to the shape<br>
  // of the objects (by opposition to the content of the object, with<br>  // the StatisticsLabelObejct).<br>  typedef unsigned long LabelType;<br>  <br>  typedef itk::ShapeLabelObject&lt; LabelType, 3 &gt; LabelObjectType;<br>
  <br>  typedef itk::LabelMap&lt; LabelObjectType &gt; LabelMapType;<br><br>  // convert the image in a collection of objects<br>  typedef itk::BinaryImageToLabelMapFilter&lt; OutputImageType, LabelMapType &gt; ConverterType;<br>
  <br>  ConverterType::Pointer converter = ConverterType::New();<br>  <br>  //ADDED after email<br>  connectedThreshold-&gt;Update();<br>  //END OF ADDED code<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">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>  //converter-&gt;SetInput( connectedThreshold-&gt;GetOutput() );<br>
  converter-&gt;SetInput( relabeler-&gt;GetOutput() );<br><br>  //converter-&gt;SetForegroundValue( atoi(argv[2]) );<br>  //converter-&gt;SetForegroundValue( 255 );<br><br>  // valuate the attributes with the dedicated filter: ShapeLabelMapFilter<br>
<br>  typedef itk::ShapeLabelMapFilter&lt; LabelMapType &gt; ShapeFilterType;<br>  ShapeFilterType::Pointer shape = ShapeFilterType::New();<br>  shape-&gt;SetInput( converter-&gt;GetOutput() );<br><br>  shape-&gt;Update();<br>
<br><br>  // then we can read the attribute values we&#39;re interested in. The BinaryImageToShapeLabelMapFilter<br>  // produce consecutive labels, so we can use a for loop and GetLabelObject() method to retrieve<br>  // the label objects. If the labels are not consecutive, the GetNthLabelObject() method must be<br>
  // use instead of GetLabelObject(), or an iterator on the label object container of the label map.<br>  LabelMapType::Pointer labelMap = shape-&gt;GetOutput();<br><br>  std::cout &lt;&lt; &quot;Number of label objects = &quot; &lt;&lt; labelMap-&gt;GetNumberOfLabelObjects() &lt;&lt; std::endl;<br>
<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>  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>  std::cout &lt;&lt; &quot;output from reader-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>  std::cout &lt;&lt; reader-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>
  <br>  std::cout &lt;&lt; &quot;output from castFilter-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>  std::cout &lt;&lt; castFilter-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>  <br>  std::cout &lt;&lt; &quot;output from connectedThreshold-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; connectedThreshold-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br><br>  std::cout &lt;&lt; &quot;output from caster-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>  std::cout &lt;&lt; caster-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>
<br>  return 0;<br>}<br><br>and output:<br>[jdrozd@trumpet ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$ make<br>Scanning dependencies of target ConnectedThresholdImageFilter                                 <br>
[100%] Building CXX object CMakeFiles/ConnectedThresholdImageFilter.dir/ConnectedThresholdImageFilter.o                                                      <br>In file included from /usr/lib/gcc/x86_64-redhat-linux/4.3.2/../../../../include/c++/4.3.2/ext/hash_map:64,                                                  <br>
                 from /trumpet/downloads/3DSlicerDec22009/Slicer3-lib/Insight/Code/Common/itk_hash_map.h:69,                                                 <br>                 from /trumpet/downloads/3DSlicerDec22009/Slicer3-lib/Insight/Code/BasicFilters/itkRelabelComponentImageFilter.txx:25,                       <br>
                 from /trumpet/downloads/3DSlicerDec22009/Slicer3-lib/Insight/Code/BasicFilters/itkRelabelComponentImageFilter.h:298,                        <br>                 from /trumpet/downloads/ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter_Plugin/ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter/ConnectedThresholdImageFilter.cxx:65:                                                                                     <br>
/usr/lib/gcc/x86_64-redhat-linux/4.3.2/../../../../include/c++/4.3.2/backward/backward_warning.h:33:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.             <br>
Linking CXX executable ConnectedThresholdImageFilter                                                                                                         <br>[100%] Built target ConnectedThresholdImageFilter                                                                                                            <br>
[jdrozd@trumpet ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$ ./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103 142 95 17100 17300                                                                                                                                    <br>
[103, 142, 95]                                                                                                                                               <br>��H��H�}�H�U�H��9(ConnectedThresholdImageFilter (0xe37580)                                                                                                   <br>
                                        RTTI typeinfo:   itk::ConnectedThresholdImageFilter&lt;itk::Image&lt;float, 3u&gt;, itk::Image&lt;float, 3u&gt; &gt;                   <br>                                        Reference Count: 1                                                                                                   <br>
                                        Modified Time: 376                                                                                                   <br>                                        Debug: Off                                                                                                           <br>
                                        Observers:                                                                                                           <br>                                        none                                                                                                                 <br>
                                        Number Of Required Inputs: 1                                                                                         <br>                                        Number Of Required Outputs: 1                                                                                        <br>
                                        Number Of Threads: 8                                                                                                 <br>                                        ReleaseDataFlag: Off                                                                                                 <br>
                                        ReleaseDataBeforeUpdateFlag: Off                                                                                     <br>                                        Input 0: (0xe49e50)                                                                                                  <br>
                                        Input 1: (0xe399b0)                                                                                                  <br>                                        Input 2: (0xe37980)                                                                                                  <br>
                                        Output 0: (0xe376a0)                                                                                                 <br>                                        AbortGenerateData: Off                                                                                               <br>
                                        Progress: 0                                                                                                          <br>                                        Multithreader:                                                                                                       <br>
                                        RTTI typeinfo:   itk::MultiThreader                                                                                  <br>                                        Reference Count: 1                                                                                                   <br>
                                        Modified Time: 82                                                                                                    <br>                                        Debug: Off                                                                                                           <br>
                                        Observers:                                                                                                           <br>                                        none                                                                                                                 <br>
                                        Thread Count: 8<br>                                        Global Maximum Number Of Threads: 128<br>                                        Global Default Number Of Threads: 8<br>                                        Upper: 3.40282e+38<br>
                                        Lower: -3.40282e+38<br>                                        ReplaceValue: 255<br>                                        Connectivity: 0<br>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>Number of label objects = 0<br>output from reader-&gt;GetOutput()-&gt;GetDirection()<br>0 0 1<br>0 1 0<br>-1 0 0<br>
<br>output from castFilter-&gt;GetOutput()-&gt;GetDirection()<br>0 0 1<br>0 1 0<br>-1 0 0<br><br>output from connectedThreshold-&gt;GetOutput()-&gt;GetDirection()<br>0 0 1<br>0 1 0<br>-1 0 0<br><br>output from caster-&gt;GetOutput()-&gt;GetDirection()<br>
0 0 1<br>0 1 0<br>-1 0 0<br><br>[jdrozd@trumpet ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$<br><br><br><br><div class="gmail_quote">On Tue, Dec 8, 2009 at 2:38 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,<br><br>I have segmented the ventricles from an image using a connected threshold image filter.<br>
I then tried to convert my outputted segmentation to a label map filter and then to get the label&#39;s attributes.<br>
<br>I am using parts of the example code attribute_values.cxx that is described in section 9.4 of<br>Gaetan Lehmann&#39;s paper: &quot;Label object representation and manipulation with ITK&quot;<br> <br>My problem is that my code is telling me that the number of labels is 0.<br>

How do I apply a label to my segmented ventricles?<br><br>Below is my code:<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>//#include &quot;itkStatisticsLabelObject.h&quot;<br><br>#include &quot;itkLabelMap.h&quot;<br>

<br>#include &quot;itkBinaryImageToShapeLabelMapFilter.h&quot;<br>//#include &quot;itkBinaryImageToStatisticsLabelMapFilter.h&quot;<br><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>  std::cout &lt;&lt; index &lt;&lt; std::endl;<br><br>  // 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>  connectedThreshold-&gt;Print(std::cout,17100);<br> <br>  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>  //added per attribute_values.cxx<br><br>  // define the object type. Here the ShapeLabelObject type<br>  // is chosen in order to read some attribute related to the shape<br>

  // of the objects (by opposition to the content of the object, with<br>  // the StatisticsLabelObejct).<br>  typedef unsigned long LabelType;<br>  <br>  typedef itk::ShapeLabelObject&lt; LabelType, 3 &gt; LabelObjectType;<br>

  <br>  typedef itk::LabelMap&lt; LabelObjectType &gt; LabelMapType;<br><br>  // convert the image in a collection of objects<br>  typedef itk::BinaryImageToLabelMapFilter&lt; InternalImageType, LabelMapType &gt; ConverterType;<br>

  <br>  ConverterType::Pointer converter = ConverterType::New();<br>  <br>  converter-&gt;SetInput( connectedThreshold-&gt;GetOutput() );<br><br>  //converter-&gt;SetForegroundValue( atoi(argv[2]) );<br>  //converter-&gt;SetForegroundValue( 255 );<br>

<br>  // valuate the attributes with the dedicated filter: ShapeLabelMapFilter<br><br>  typedef itk::ShapeLabelMapFilter&lt; LabelMapType &gt; ShapeFilterType;<br>  ShapeFilterType::Pointer shape = ShapeFilterType::New();<br>

  shape-&gt;SetInput( converter-&gt;GetOutput() );<br><br>  shape-&gt;Update();<br><br><br>  // then we can read the attribute values we&#39;re interested in. The BinaryImageToShapeLabelMapFilter<br>  // produce consecutive labels, so we can use a for loop and GetLabelObject() method to retrieve<br>

  // the label objects. If the labels are not consecutive, the GetNthLabelObject() method must be<br>  // use instead of GetLabelObject(), or an iterator on the label object container of the label map.<br>  LabelMapType::Pointer labelMap = shape-&gt;GetOutput();<br>

<br>  std::cout &lt;&lt; &quot;Number of label objects = &quot; &lt;&lt; labelMap-&gt;GetNumberOfLabelObjects() &lt;&lt; std::endl;<br><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>  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>  std::cout &lt;&lt; &quot;output from reader-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>  std::cout &lt;&lt; reader-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>  <br>  std::cout &lt;&lt; &quot;output from castFilter-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>

  std::cout &lt;&lt; castFilter-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>  <br>  std::cout &lt;&lt; &quot;output from connectedThreshold-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>  std::cout &lt;&lt; connectedThreshold-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>

<br>  std::cout &lt;&lt; &quot;output from caster-&gt;GetOutput()-&gt;GetDirection()&quot; &lt;&lt; std::endl;<br>  std::cout &lt;&lt; caster-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br><br>  return 0;<br>}<br>

<br>
</blockquote></div><br>