[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
Fri Dec 11 14:05:50 EST 2009


Hi,

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.

Thanks,
john

On Fri, Dec 11, 2009 at 1:58 PM, John Drozd <john.drozd at gmail.com> wrote:

> Hello Luis, Richard and Bonjour Gaetan,
>
> Thank you all for helping me.  My code works now giving me the correct
> output:
>
> [jdrozd at trumpetConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$
> ./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103
> 142 95 17100 17300
> labelMap->GetNumberOfLabelObjects() = 1
> 1       23901.3 [294.881, 123.841, -97.2387]
>
>  Below is my code to complete the communication thread (and thanks again):
>
>
> /*
> 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 "itkLabelMap.h"
>
> #include "itkBinaryImageToShapeLabelMapFilter.h"
> //end of added code
>
> //added per label.cxx
> #include "itkLabelObject.h"
> #include "itkLabelMap.h"
> #include "itkBinaryImageToLabelMapFilter.h"
> #include "itkLabelMapToLabelImageFilter.h"
> //end of added code
>
> #include "itkSimpleFilterWatcher.h"
>
>
> 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   unsigned char          BinaryPixelType;
>
>
>   const     unsigned int    Dimension = 3;
>
>   typedef itk::Image< BinaryPixelType, Dimension >  BinaryImageType;
>
>
>   typedef signed short InputPixelType;
>
>   typedef itk::Image< InputPixelType, Dimension > InputImageType;
>   typedef unsigned char LabelType;
>   const unsigned int dim = 3;
>   typedef itk::ShapeLabelObject< LabelType, dim > LabelObjectType;
>
>   typedef itk::LabelMap< LabelObjectType > LabelMapType;
>   typedef itk::BinaryImageToShapeLabelMapFilter< BinaryImageType,
> LabelMapType> ConverterType;
>
>
>   ConverterType::Pointer converter = ConverterType::New();
>
>   typedef  itk::ImageFileReader< InputImageType > ReaderType;
>   typedef  itk::ImageFileWriter<  BinaryImageType  > WriterType;
>
>
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::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::ConnectedThresholdImageFilter< InputImageType,
>                                     BinaryImageType > ConnectedFilterType;
>
>
>   ConnectedFilterType::Pointer connectedThreshold =
> ConnectedFilterType::New();
>
>   connectedThreshold->SetInput( reader->GetOutput() );
>
>   const InputPixelType lowerThreshold = atof( argv[6] );
>   const InputPixelType upperThreshold = atof( argv[7] );
>
>
>   connectedThreshold->SetLower(  lowerThreshold  );
>   connectedThreshold->SetUpper(  upperThreshold  );
>
>   connectedThreshold->SetReplaceValue( 255 );
>
>   BinaryImageType::IndexType  index;
>
>
>   index[0] = atoi( argv[3] );
>   index[1] = atoi( argv[4] );
>
>   //added
>   index[2] = atoi( argv[5] );
>
>   // 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 );
>     }
>
>   typedef itk::MetaDataDictionary DictionaryType;
>
>   DictionaryType inputdict = reader->GetMetaDataDictionary();
>
>   writer->SetMetaDataDictionary( inputdict );
>
>   writer->SetFileName( argv[2] );
>
>   connectedThreshold->Update();
>
>   converter->SetInput( connectedThreshold->GetOutput() );
>
>   converter->SetFullyConnected( true );
>
>   converter->SetInputForegroundValue( 255 );
>
>   converter->SetOutputBackgroundValue( 0 );
>
>   converter->Update();
>
>   LabelMapType::Pointer labelMap = converter->GetOutput();
>
>   std::cout << "labelMap->GetNumberOfLabelObjects() = " <<
> 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;
>     }
>
>   typedef itk::LabelMapToLabelImageFilter< LabelMapType, BinaryImageType >
> L2IType;
>
>
>   L2IType::Pointer l2i = L2IType::New();
>
>   l2i->SetInput( converter->GetOutput() );
>
>   writer->SetInput( l2i->GetOutput() );
>
>
>   try
>     {
>     writer->Update();
>     }
>   catch( itk::ExceptionObject & excep )
>     {
>     std::cerr << "Exception caught !" << std::endl;
>     std::cerr << excep << std::endl;
>     }
>
>   return 0;
>
> }
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091211/9cbef382/attachment.htm>


More information about the Insight-users mailing list