[Insight-users] combining output from segmentation with label map attributes using Gaetan Lehmann's paper: "Label object representation and manipulation with ITK"

John Drozd john.drozd at gmail.com
Tue Dec 8 17:30:42 EST 2009


Hi again,

I reverted to using an antiquated "RelabelComponentImageFilter.h" header to
get the volume of the ventricles, *but is there a way to get the physical
size using a non-antiquated currently used header?*

I used:

//ADDED PER WEB PAGE
  //
http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html
  typedef itk::ConnectedComponentImageFilter <OutputImageType,
OutputImageType>  LabelType2;
  typedef itk::RelabelComponentImageFilter <OutputImageType,
OutputImageType> RelabelType;

  LabelType2::Pointer labeler = LabelType2::New();
  RelabelType::Pointer relabeler = RelabelType::New();

  labeler->SetInput(caster->GetOutput());
  labeler->Update();

  relabeler->SetInput(labeler->GetOutput());
  relabeler->Update();

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

    std::cout<<"Physical size for object "<<i<<":
"<<relabeler->GetSizeOfObjectsInPhysicalUnits()[i]<<std::endl;
    }
  //END OF ADDED CODE

This gave me a ventricle size of
Number of pixel for object 0: 22129
Physical size for object 0: 23901

When I created a label map using the gui in 3DSlicer, I got a similar size
but not exactly the same size:
Number of pixel for object 0: 22130
Physical size for object 0: 23901.284681

Below is the updated code:

/*
to run type:
./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103
142 95 17100 17300
*/

#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif


#include "itkConnectedThresholdImageFilter.h"

#include "itkImage.h"
#include "itkCastImageFilter.h"

#include "itkCurvatureFlowImageFilter.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkGDCMImageIO.h"

#include "itkVersion.h"

#include "itkOrientedImage.h"
#include "itkMinimumMaximumImageFilter.h"

#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkNumericSeriesFileNames.h"

#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"

#include "itkResampleImageFilter.h"
#include "itkShiftScaleImageFilter.h"

#include "itkIdentityTransform.h"
#include "itkLinearInterpolateImageFunction.h"

#include <itksys/SystemTools.hxx>

#include "gdcm/src/gdcmFile.h"
#include "gdcm/src/gdcmUtil.h"

#include <string>

//added per attribute_values.cxx
#include "itkImageFileReader.h"

#include "itkShapeLabelObject.h"
//#include "itkStatisticsLabelObject.h"

#include "itkLabelMap.h"

#include "itkBinaryImageToShapeLabelMapFilter.h"
//#include "itkBinaryImageToStatisticsLabelMapFilter.h"

//ADDED PER WEB PAGE
//
http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html
#include "itkConnectedComponentImageFilter.h"
#include "itkRelabelComponentImageFilter.h"
//END OF ADDED CODE

//end of added code

int main( int argc, char *argv[])
{
  if( argc < 7 )
    {
    std::cerr << "Missing Parameters " << std::endl;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " inputImage  outputImage seedX seedY seedZ lowerThreshold
upperThreshold" << std::endl;

    return 1;
    }

  typedef   float           InternalPixelType;

  const     unsigned int    Dimension = 3;

  typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;

  typedef signed short OutputPixelType;

  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
  typedef itk::Image< float, Dimension > OutputImageType2;
  typedef itk::CastImageFilter< InternalImageType, OutputImageType >
    CastingFilterType;
  CastingFilterType::Pointer caster = CastingFilterType::New();

  const    unsigned int    ImageDimension = 3;
  typedef  signed short    PixelType;

  typedef itk::Image< PixelType, ImageDimension >  FixedImageType;
  typedef itk::Image< float, ImageDimension >  FloatImageType;

  typedef  itk::ImageFileReader< FixedImageType > ReaderType;
  typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
  typedef  itk::ImageFileWriter<  FloatImageType  > WriterType2;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  WriterType2::Pointer writer2 = WriterType2::New();

  typedef itk::GDCMImageIO           ImageIOTypefixed;
  ImageIOTypefixed::Pointer gdcmImageIOfixed = ImageIOTypefixed::New();
  reader->SetImageIO( gdcmImageIOfixed );

  typedef itk::GDCMImageIO           ImageIOTypefixed2;
  ImageIOTypefixed2::Pointer gdcmImageIOfixed2 = ImageIOTypefixed2::New();

  reader->SetFileName( argv[1] );

  reader->Update();

  typedef itk::CurvatureFlowImageFilter< InternalImageType,
InternalImageType >
    CurvatureFlowImageFilterType;

  CurvatureFlowImageFilterType::Pointer smoothing =
                         CurvatureFlowImageFilterType::New();

  typedef itk::ConnectedThresholdImageFilter< InternalImageType,
                                    InternalImageType > ConnectedFilterType;

  ConnectedFilterType::Pointer connectedThreshold =
ConnectedFilterType::New();

  typedef signed short InputAPixelType;
  typedef float OutputBPixelType;

  typedef itk::Image< InputAPixelType, 3 > InputAImageType;
  typedef itk::Image< OutputBPixelType, 3 > OutputBImageType;

  typedef itk::CastImageFilter< InputAImageType, OutputBImageType >
CastFilterType;

  CastFilterType::Pointer castFilter = CastFilterType::New();


  castFilter->SetInput( reader->GetOutput() );


  connectedThreshold->SetInput( castFilter->GetOutput() );

  caster->SetInput( connectedThreshold->GetOutput() );


  smoothing->SetNumberOfIterations( 20 ); //was 5
  smoothing->SetTimeStep( 0.125 );

  const InternalPixelType lowerThreshold = atof( argv[6] );
  const InternalPixelType upperThreshold = atof( argv[7] );

  connectedThreshold->SetLower(  lowerThreshold  );
  connectedThreshold->SetUpper(  upperThreshold  );

  connectedThreshold->SetReplaceValue( 255 );

  InternalImageType::IndexType  index;

  index[0] = atoi( argv[3] );
  index[1] = atoi( argv[4] );

  //added
  index[2] = atoi( argv[5] );

  std::cout << index << std::endl;

  // Software Guide : BeginCodeSnippet
  connectedThreshold->SetSeed( index );

  //obtain a 5 x 5 bounding region of seeds
  int ii, jj, kk;

  ii = index[0];
  jj = index[1];
  kk = index[2];

  for (int i = ii; i < ii + 5; i++)
    for (int j = jj; j < jj + 5; j++)
      for (int k = kk; k < kk + 5; k++)
    {

      index[0] = i;
      index[1] = j;
      index[2] = k;
      connectedThreshold->AddSeed( index );
    }

  for (int i = ii; i > ii - 5; i--)
    for (int j = jj; j > jj - 5; j--)
      for (int k = kk; k > kk - 5; k--)
    {

      index[0] = i;
      index[1] = j;
      index[2] = k;
      connectedThreshold->AddSeed( index );
    }

  connectedThreshold->Print(std::cout,17100);

  typedef itk::MetaDataDictionary DictionaryType;

  DictionaryType inputdict = reader->GetMetaDataDictionary();

  writer->SetMetaDataDictionary( inputdict );

  writer->SetFileName( argv[2] );

  //added per attribute_values.cxx

  // define the object type. Here the ShapeLabelObject type
  // is chosen in order to read some attribute related to the shape
  // of the objects (by opposition to the content of the object, with
  // the StatisticsLabelObejct).
  typedef unsigned long LabelType;

  typedef itk::ShapeLabelObject< LabelType, 3 > LabelObjectType;

  typedef itk::LabelMap< LabelObjectType > LabelMapType;

  // convert the image in a collection of objects
  typedef itk::BinaryImageToLabelMapFilter< OutputImageType, LabelMapType >
ConverterType;

  ConverterType::Pointer converter = ConverterType::New();

  //ADDED after email
  connectedThreshold->Update();
  //END OF ADDED code

  //ADDED PER WEB PAGE
  //
http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html
  typedef itk::ConnectedComponentImageFilter <OutputImageType,
OutputImageType>  LabelType2;
  typedef itk::RelabelComponentImageFilter <OutputImageType,
OutputImageType> RelabelType;

  LabelType2::Pointer labeler = LabelType2::New();
  RelabelType::Pointer relabeler = RelabelType::New();

  labeler->SetInput(caster->GetOutput());
  labeler->Update();

  relabeler->SetInput(labeler->GetOutput());
  relabeler->Update();

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

    std::cout<<"Physical size for object "<<i<<":
"<<relabeler->GetSizeOfObjectsInPhysicalUnits()[i]<<std::endl;
    }
  //END OF ADDED CODE

  //converter->SetInput( connectedThreshold->GetOutput() );
  converter->SetInput( relabeler->GetOutput() );

  //converter->SetForegroundValue( atoi(argv[2]) );
  //converter->SetForegroundValue( 255 );

  // valuate the attributes with the dedicated filter: ShapeLabelMapFilter

  typedef itk::ShapeLabelMapFilter< LabelMapType > ShapeFilterType;
  ShapeFilterType::Pointer shape = ShapeFilterType::New();
  shape->SetInput( converter->GetOutput() );

  shape->Update();


  // then we can read the attribute values we're interested in. The
BinaryImageToShapeLabelMapFilter
  // produce consecutive labels, so we can use a for loop and
GetLabelObject() method to retrieve
  // the label objects. If the labels are not consecutive, the
GetNthLabelObject() method must be
  // use instead of GetLabelObject(), or an iterator on the label object
container of the label map.
  LabelMapType::Pointer labelMap = shape->GetOutput();

  std::cout << "Number of label objects = " <<
labelMap->GetNumberOfLabelObjects() << std::endl;


  for( unsigned int label=1; label<=labelMap->GetNumberOfLabelObjects();
label++ )
    {
    // we don't need a SmartPointer of the label object here, because the
reference is kept in
    // in the label map.
    const LabelObjectType * labelObject = labelMap->GetLabelObject( label );
    std::cout << label << "\t" << labelObject->GetPhysicalSize() << "\t" <<
labelObject->GetCentroid() << std::endl;
    }

  writer->SetInput( caster->GetOutput() );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    }

  std::cout << "output from reader->GetOutput()->GetDirection()" <<
std::endl;
  std::cout << reader->GetOutput()->GetDirection() << std::endl;

  std::cout << "output from castFilter->GetOutput()->GetDirection()" <<
std::endl;
  std::cout << castFilter->GetOutput()->GetDirection() << std::endl;

  std::cout << "output from connectedThreshold->GetOutput()->GetDirection()"
<< std::endl;
  std::cout << connectedThreshold->GetOutput()->GetDirection() << std::endl;

  std::cout << "output from caster->GetOutput()->GetDirection()" <<
std::endl;
  std::cout << caster->GetOutput()->GetDirection() << std::endl;

  return 0;
}

and output:
[jdrozd at trumpetConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$
make
Scanning dependencies of target
ConnectedThresholdImageFilter
[100%] Building CXX object
CMakeFiles/ConnectedThresholdImageFilter.dir/ConnectedThresholdImageFilter.o

In file included from
/usr/lib/gcc/x86_64-redhat-linux/4.3.2/../../../../include/c++/4.3.2/ext/hash_map:64,

                 from
/trumpet/downloads/3DSlicerDec22009/Slicer3-lib/Insight/Code/Common/itk_hash_map.h:69,

                 from
/trumpet/downloads/3DSlicerDec22009/Slicer3-lib/Insight/Code/BasicFilters/itkRelabelComponentImageFilter.txx:25,

                 from
/trumpet/downloads/3DSlicerDec22009/Slicer3-lib/Insight/Code/BasicFilters/itkRelabelComponentImageFilter.h:298,

                 from
/trumpet/downloads/ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter_Plugin/ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter/ConnectedThresholdImageFilter.cxx:65:

/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.

Linking CXX executable
ConnectedThresholdImageFilter

[100%] Built target
ConnectedThresholdImageFilter

[jdrozd at trumpetConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$
./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103
142 95 17100
17300

[103, 142,
95]

��H��H�}�H�U�H��9(ConnectedThresholdImageFilter
(0xe37580)

                                        RTTI typeinfo:
itk::ConnectedThresholdImageFilter<itk::Image<float, 3u>, itk::Image<float,
3u> >
                                        Reference Count:
1

                                        Modified Time:
376

                                        Debug:
Off


Observers:


none

                                        Number Of Required Inputs:
1

                                        Number Of Required Outputs:
1

                                        Number Of Threads:
8

                                        ReleaseDataFlag:
Off

                                        ReleaseDataBeforeUpdateFlag:
Off

                                        Input 0:
(0xe49e50)

                                        Input 1:
(0xe399b0)

                                        Input 2:
(0xe37980)

                                        Output 0:
(0xe376a0)

                                        AbortGenerateData:
Off

                                        Progress:
0


Multithreader:

                                        RTTI typeinfo:
itk::MultiThreader

                                        Reference Count:
1

                                        Modified Time:
82

                                        Debug:
Off


Observers:


none

                                        Thread Count: 8
                                        Global Maximum Number Of Threads:
128
                                        Global Default Number Of Threads: 8
                                        Upper: 3.40282e+38
                                        Lower: -3.40282e+38
                                        ReplaceValue: 255
                                        Connectivity: 0
Number of pixel for object 0: 22129
Physical size for object 0: 23901
Number of pixel for object 1: 1
Physical size for object 1: 1.08004
Number of label objects = 0
output from reader->GetOutput()->GetDirection()
0 0 1
0 1 0
-1 0 0

output from castFilter->GetOutput()->GetDirection()
0 0 1
0 1 0
-1 0 0

output from connectedThreshold->GetOutput()->GetDirection()
0 0 1
0 1 0
-1 0 0

output from caster->GetOutput()->GetDirection()
0 0 1
0 1 0
-1 0 0

[jdrozd at trumpetConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$



On Tue, Dec 8, 2009 at 2:38 PM, John Drozd <john.drozd at gmail.com> wrote:

> Hello,
>
> I have segmented the ventricles from an image using a connected threshold
> image filter.
> I then tried to convert my outputted segmentation to a label map filter and
> then to get the label's attributes.
>
> I am using parts of the example code attribute_values.cxx that is described
> in section 9.4 of
> Gaetan Lehmann's paper: "Label object representation and manipulation with
> ITK"
>
> My problem is that my code is telling me that the number of labels is 0.
> How do I apply a label to my segmented ventricles?
>
> Below is my code:
>
> /*
> to run type:
> ./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103
> 142 95 17100 17300
> */
>
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
> #ifdef __BORLANDC__
> #define ITK_LEAN_AND_MEAN
> #endif
>
>
> #include "itkConnectedThresholdImageFilter.h"
>
> #include "itkImage.h"
> #include "itkCastImageFilter.h"
>
> #include "itkCurvatureFlowImageFilter.h"
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkGDCMImageIO.h"
>
> #include "itkVersion.h"
>
> #include "itkOrientedImage.h"
> #include "itkMinimumMaximumImageFilter.h"
>
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkNumericSeriesFileNames.h"
>
> #include "itkImageSeriesReader.h"
> #include "itkImageSeriesWriter.h"
>
> #include "itkResampleImageFilter.h"
> #include "itkShiftScaleImageFilter.h"
>
> #include "itkIdentityTransform.h"
> #include "itkLinearInterpolateImageFunction.h"
>
> #include <itksys/SystemTools.hxx>
>
> #include "gdcm/src/gdcmFile.h"
> #include "gdcm/src/gdcmUtil.h"
>
> #include <string>
>
> //added per attribute_values.cxx
> #include "itkImageFileReader.h"
>
> #include "itkShapeLabelObject.h"
> //#include "itkStatisticsLabelObject.h"
>
> #include "itkLabelMap.h"
>
> #include "itkBinaryImageToShapeLabelMapFilter.h"
> //#include "itkBinaryImageToStatisticsLabelMapFilter.h"
>
> //end of added code
>
> int main( int argc, char *argv[])
> {
>   if( argc < 7 )
>     {
>     std::cerr << "Missing Parameters " << std::endl;
>     std::cerr << "Usage: " << argv[0];
>     std::cerr << " inputImage  outputImage seedX seedY seedZ lowerThreshold
> upperThreshold" << std::endl;
>
>     return 1;
>     }
>
>   typedef   float           InternalPixelType;
>
>   const     unsigned int    Dimension = 3;
>
>   typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
>
>   typedef signed short OutputPixelType;
>
>   typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
>   typedef itk::Image< float, Dimension > OutputImageType2;
>   typedef itk::CastImageFilter< InternalImageType, OutputImageType >
>     CastingFilterType;
>   CastingFilterType::Pointer caster = CastingFilterType::New();
>
>   const    unsigned int    ImageDimension = 3;
>   typedef  signed short    PixelType;
>
>   typedef itk::Image< PixelType, ImageDimension >  FixedImageType;
>   typedef itk::Image< float, ImageDimension >  FloatImageType;
>
>   typedef  itk::ImageFileReader< FixedImageType > ReaderType;
>   typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
>   typedef  itk::ImageFileWriter<  FloatImageType  > WriterType2;
>
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::New();
>   WriterType2::Pointer writer2 = WriterType2::New();
>
>   typedef itk::GDCMImageIO           ImageIOTypefixed;
>   ImageIOTypefixed::Pointer gdcmImageIOfixed = ImageIOTypefixed::New();
>   reader->SetImageIO( gdcmImageIOfixed );
>
>   typedef itk::GDCMImageIO           ImageIOTypefixed2;
>   ImageIOTypefixed2::Pointer gdcmImageIOfixed2 = ImageIOTypefixed2::New();
>
>   reader->SetFileName( argv[1] );
>
>   reader->Update();
>
>   typedef itk::CurvatureFlowImageFilter< InternalImageType,
> InternalImageType >
>     CurvatureFlowImageFilterType;
>
>   CurvatureFlowImageFilterType::Pointer smoothing =
>                          CurvatureFlowImageFilterType::New();
>
>   typedef itk::ConnectedThresholdImageFilter< InternalImageType,
>                                     InternalImageType >
> ConnectedFilterType;
>
>   ConnectedFilterType::Pointer connectedThreshold =
> ConnectedFilterType::New();
>
>   typedef signed short InputAPixelType;
>   typedef float OutputBPixelType;
>
>   typedef itk::Image< InputAPixelType, 3 > InputAImageType;
>   typedef itk::Image< OutputBPixelType, 3 > OutputBImageType;
>
>   typedef itk::CastImageFilter< InputAImageType, OutputBImageType >
> CastFilterType;
>
>   CastFilterType::Pointer castFilter = CastFilterType::New();
>
>
>   castFilter->SetInput( reader->GetOutput() );
>
>
>   connectedThreshold->SetInput( castFilter->GetOutput() );
>
>   caster->SetInput( connectedThreshold->GetOutput() );
>
>
>   smoothing->SetNumberOfIterations( 20 ); //was 5
>   smoothing->SetTimeStep( 0.125 );
>
>   const InternalPixelType lowerThreshold = atof( argv[6] );
>   const InternalPixelType upperThreshold = atof( argv[7] );
>
>   connectedThreshold->SetLower(  lowerThreshold  );
>   connectedThreshold->SetUpper(  upperThreshold  );
>
>   connectedThreshold->SetReplaceValue( 255 );
>
>   InternalImageType::IndexType  index;
>
>   index[0] = atoi( argv[3] );
>   index[1] = atoi( argv[4] );
>
>   //added
>   index[2] = atoi( argv[5] );
>
>   std::cout << index << std::endl;
>
>   // Software Guide : BeginCodeSnippet
>   connectedThreshold->SetSeed( index );
>
>   //obtain a 5 x 5 bounding region of seeds
>   int ii, jj, kk;
>
>   ii = index[0];
>   jj = index[1];
>   kk = index[2];
>
>   for (int i = ii; i < ii + 5; i++)
>     for (int j = jj; j < jj + 5; j++)
>       for (int k = kk; k < kk + 5; k++)
>     {
>
>       index[0] = i;
>       index[1] = j;
>       index[2] = k;
>       connectedThreshold->AddSeed( index );
>     }
>
>   for (int i = ii; i > ii - 5; i--)
>     for (int j = jj; j > jj - 5; j--)
>       for (int k = kk; k > kk - 5; k--)
>     {
>
>       index[0] = i;
>       index[1] = j;
>       index[2] = k;
>       connectedThreshold->AddSeed( index );
>     }
>
>   connectedThreshold->Print(std::cout,17100);
>
>   typedef itk::MetaDataDictionary DictionaryType;
>
>   DictionaryType inputdict = reader->GetMetaDataDictionary();
>
>   writer->SetMetaDataDictionary( inputdict );
>
>   writer->SetFileName( argv[2] );
>
>   //added per attribute_values.cxx
>
>   // define the object type. Here the ShapeLabelObject type
>   // is chosen in order to read some attribute related to the shape
>   // of the objects (by opposition to the content of the object, with
>   // the StatisticsLabelObejct).
>   typedef unsigned long LabelType;
>
>   typedef itk::ShapeLabelObject< LabelType, 3 > LabelObjectType;
>
>   typedef itk::LabelMap< LabelObjectType > LabelMapType;
>
>   // convert the image in a collection of objects
>   typedef itk::BinaryImageToLabelMapFilter< InternalImageType, LabelMapType
> > ConverterType;
>
>   ConverterType::Pointer converter = ConverterType::New();
>
>   converter->SetInput( connectedThreshold->GetOutput() );
>
>   //converter->SetForegroundValue( atoi(argv[2]) );
>   //converter->SetForegroundValue( 255 );
>
>   // valuate the attributes with the dedicated filter: ShapeLabelMapFilter
>
>   typedef itk::ShapeLabelMapFilter< LabelMapType > ShapeFilterType;
>   ShapeFilterType::Pointer shape = ShapeFilterType::New();
>   shape->SetInput( converter->GetOutput() );
>
>   shape->Update();
>
>
>   // then we can read the attribute values we're interested in. The
> BinaryImageToShapeLabelMapFilter
>   // produce consecutive labels, so we can use a for loop and
> GetLabelObject() method to retrieve
>   // the label objects. If the labels are not consecutive, the
> GetNthLabelObject() method must be
>   // use instead of GetLabelObject(), or an iterator on the label object
> container of the label map.
>   LabelMapType::Pointer labelMap = shape->GetOutput();
>
>   std::cout << "Number of label objects = " <<
> labelMap->GetNumberOfLabelObjects() << std::endl;
>
>
>   for( unsigned int label=1; label<=labelMap->GetNumberOfLabelObjects();
> label++ )
>     {
>     // we don't need a SmartPointer of the label object here, because the
> reference is kept in
>     // in the label map.
>     const LabelObjectType * labelObject = labelMap->GetLabelObject( label
> );
>     std::cout << label << "\t" << labelObject->GetPhysicalSize() << "\t" <<
> labelObject->GetCentroid() << std::endl;
>     }
>
>   writer->SetInput( caster->GetOutput() );
>
>   try
>     {
>     writer->Update();
>     }
>   catch( itk::ExceptionObject & excep )
>     {
>     std::cerr << "Exception caught !" << std::endl;
>     std::cerr << excep << std::endl;
>     }
>
>   std::cout << "output from reader->GetOutput()->GetDirection()" <<
> std::endl;
>   std::cout << reader->GetOutput()->GetDirection() << std::endl;
>
>   std::cout << "output from castFilter->GetOutput()->GetDirection()" <<
> std::endl;
>   std::cout << castFilter->GetOutput()->GetDirection() << std::endl;
>
>   std::cout << "output from
> connectedThreshold->GetOutput()->GetDirection()" << std::endl;
>   std::cout << connectedThreshold->GetOutput()->GetDirection() <<
> std::endl;
>
>   std::cout << "output from caster->GetOutput()->GetDirection()" <<
> std::endl;
>   std::cout << caster->GetOutput()->GetDirection() << std::endl;
>
>   return 0;
> }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091208/8ae1813c/attachment-0001.htm>


More information about the Insight-users mailing list