Hi again,<br><br>I reverted to using an antiquated "RelabelComponentImageFilter.h" 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 <OutputImageType, OutputImageType> LabelType2;<br> typedef itk::RelabelComponentImageFilter <OutputImageType, OutputImageType> RelabelType;<br><br> LabelType2::Pointer labeler = LabelType2::New();<br>
RelabelType::Pointer relabeler = RelabelType::New();<br><br> labeler->SetInput(caster->GetOutput());<br> labeler->Update();<br><br> relabeler->SetInput(labeler->GetOutput());<br> relabeler->Update();<br>
<br> for (unsigned int i=0; i<relabeler->GetNumberOfObjects(); i++)<br> {<br> std::cout<<"Number of pixel for object "<<i<<": "<<relabeler->GetSizeOfObjectsInPixels()[i]<<std::endl;<br>
<br> std::cout<<"Physical size for object "<<i<<": "<<relabeler->GetSizeOfObjectsInPhysicalUnits()[i]<<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 "itkConnectedThresholdImageFilter.h"<br><br>#include "itkImage.h"<br>#include "itkCastImageFilter.h"<br>
<br>#include "itkCurvatureFlowImageFilter.h"<br><br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br><br>#include "itkGDCMImageIO.h"<br><br>#include "itkVersion.h"<br>
<br>#include "itkOrientedImage.h"<br>#include "itkMinimumMaximumImageFilter.h"<br><br>#include "itkGDCMImageIO.h"<br>#include "itkGDCMSeriesFileNames.h"<br>#include "itkNumericSeriesFileNames.h"<br>
<br>#include "itkImageSeriesReader.h"<br>#include "itkImageSeriesWriter.h"<br><br>#include "itkResampleImageFilter.h"<br>#include "itkShiftScaleImageFilter.h"<br><br>#include "itkIdentityTransform.h"<br>
#include "itkLinearInterpolateImageFunction.h"<br><br>#include <itksys/SystemTools.hxx><br><br>#include "gdcm/src/gdcmFile.h"<br>#include "gdcm/src/gdcmUtil.h"<br><br>#include <string><br>
<br>//added per attribute_values.cxx<br>#include "itkImageFileReader.h"<br><br>#include "itkShapeLabelObject.h"<br>//#include "itkStatisticsLabelObject.h"<br><br>#include "itkLabelMap.h"<br>
<br>#include "itkBinaryImageToShapeLabelMapFilter.h"<br>//#include "itkBinaryImageToStatisticsLabelMapFilter.h"<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 "itkConnectedComponentImageFilter.h"<br>#include "itkRelabelComponentImageFilter.h"<br>//END OF ADDED CODE<br><br>//end of added code<br><br>int main( int argc, char *argv[])<br>{<br> if( argc < 7 )<br>
{<br> std::cerr << "Missing Parameters " << std::endl;<br> std::cerr << "Usage: " << argv[0];<br> std::cerr << " inputImage outputImage seedX seedY seedZ lowerThreshold upperThreshold" << std::endl;<br>
<br> return 1;<br> }<br><br> typedef float InternalPixelType;<br> <br> const unsigned int Dimension = 3;<br><br> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<br>
<br> typedef signed short OutputPixelType;<br><br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br> typedef itk::Image< float, Dimension > OutputImageType2;<br> typedef itk::CastImageFilter< InternalImageType, OutputImageType ><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< PixelType, ImageDimension > FixedImageType;<br>
typedef itk::Image< float, ImageDimension > FloatImageType;<br><br> typedef itk::ImageFileReader< FixedImageType > ReaderType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
typedef itk::ImageFileWriter< FloatImageType > 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->SetImageIO( gdcmImageIOfixed );<br><br> typedef itk::GDCMImageIO ImageIOTypefixed2;<br>
ImageIOTypefixed2::Pointer gdcmImageIOfixed2 = ImageIOTypefixed2::New();<br><br> reader->SetFileName( argv[1] );<br> <br> reader->Update();<br><br> typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType ><br>
CurvatureFlowImageFilterType;<br> <br> CurvatureFlowImageFilterType::Pointer smoothing =<br> CurvatureFlowImageFilterType::New();<br><br> typedef itk::ConnectedThresholdImageFilter< InternalImageType,<br>
InternalImageType > ConnectedFilterType;<br><br> ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();<br><br> typedef signed short InputAPixelType;<br> typedef float OutputBPixelType;<br>
<br> typedef itk::Image< InputAPixelType, 3 > InputAImageType;<br> typedef itk::Image< OutputBPixelType, 3 > OutputBImageType;<br><br> typedef itk::CastImageFilter< InputAImageType, OutputBImageType > CastFilterType;<br>
<br> CastFilterType::Pointer castFilter = CastFilterType::New();<br><br><br> castFilter->SetInput( reader->GetOutput() );<br> <br><br> connectedThreshold->SetInput( castFilter->GetOutput() );<br><br> caster->SetInput( connectedThreshold->GetOutput() );<br>
<br><br> smoothing->SetNumberOfIterations( 20 ); //was 5<br> smoothing->SetTimeStep( 0.125 );<br> <br> const InternalPixelType lowerThreshold = atof( argv[6] );<br> const InternalPixelType upperThreshold = atof( argv[7] );<br>
<br> connectedThreshold->SetLower( lowerThreshold );<br> connectedThreshold->SetUpper( upperThreshold );<br> <br> connectedThreshold->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 << index << std::endl;<br><br> // Software Guide : BeginCodeSnippet<br>
connectedThreshold->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 < ii + 5; i++)<br>
for (int j = jj; j < jj + 5; j++)<br> for (int k = kk; k < kk + 5; k++)<br> {<br> <br> index[0] = i;<br> index[1] = j;<br> index[2] = k;<br> connectedThreshold->AddSeed( index );<br>
}<br><br> for (int i = ii; i > ii - 5; i--)<br> for (int j = jj; j > jj - 5; j--)<br> for (int k = kk; k > kk - 5; k--)<br> {<br> <br> index[0] = i;<br> index[1] = j;<br> index[2] = k;<br>
connectedThreshold->AddSeed( index );<br> }<br><br> connectedThreshold->Print(std::cout,17100);<br> <br> typedef itk::MetaDataDictionary DictionaryType;<br> <br> DictionaryType inputdict = reader->GetMetaDataDictionary();<br>
<br> writer->SetMetaDataDictionary( inputdict );<br> <br> writer->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< LabelType, 3 > LabelObjectType;<br>
<br> typedef itk::LabelMap< LabelObjectType > LabelMapType;<br><br> // convert the image in a collection of objects<br> typedef itk::BinaryImageToLabelMapFilter< OutputImageType, LabelMapType > ConverterType;<br>
<br> ConverterType::Pointer converter = ConverterType::New();<br> <br> //ADDED after email<br> connectedThreshold->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 <OutputImageType, OutputImageType> LabelType2;<br> typedef itk::RelabelComponentImageFilter <OutputImageType, OutputImageType> RelabelType;<br><br> LabelType2::Pointer labeler = LabelType2::New();<br>
RelabelType::Pointer relabeler = RelabelType::New();<br><br> labeler->SetInput(caster->GetOutput());<br> labeler->Update();<br><br> relabeler->SetInput(labeler->GetOutput());<br> relabeler->Update();<br>
<br> for (unsigned int i=0; i<relabeler->GetNumberOfObjects(); i++)<br> {<br> std::cout<<"Number of pixel for object "<<i<<": "<<relabeler->GetSizeOfObjectsInPixels()[i]<<std::endl;<br>
<br> std::cout<<"Physical size for object "<<i<<": "<<relabeler->GetSizeOfObjectsInPhysicalUnits()[i]<<std::endl;<br> }<br> //END OF ADDED CODE<br><br> //converter->SetInput( connectedThreshold->GetOutput() );<br>
converter->SetInput( relabeler->GetOutput() );<br><br> //converter->SetForegroundValue( atoi(argv[2]) );<br> //converter->SetForegroundValue( 255 );<br><br> // valuate the attributes with the dedicated filter: ShapeLabelMapFilter<br>
<br> typedef itk::ShapeLabelMapFilter< LabelMapType > ShapeFilterType;<br> ShapeFilterType::Pointer shape = ShapeFilterType::New();<br> shape->SetInput( converter->GetOutput() );<br><br> shape->Update();<br>
<br><br> // then we can read the attribute values we'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->GetOutput();<br><br> std::cout << "Number of label objects = " << labelMap->GetNumberOfLabelObjects() << std::endl;<br>
<br><br> for( unsigned int label=1; label<=labelMap->GetNumberOfLabelObjects(); label++ )<br> {<br> // we don'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->GetLabelObject( label );<br> std::cout << label << "\t" << labelObject->GetPhysicalSize() << "\t" << labelObject->GetCentroid() << std::endl;<br>
}<br><br> writer->SetInput( caster->GetOutput() );<br><br> try<br> {<br> writer->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception caught !" << std::endl;<br>
std::cerr << excep << std::endl;<br> }<br><br> std::cout << "output from reader->GetOutput()->GetDirection()" << std::endl;<br> std::cout << reader->GetOutput()->GetDirection() << std::endl;<br>
<br> std::cout << "output from castFilter->GetOutput()->GetDirection()" << std::endl;<br> std::cout << castFilter->GetOutput()->GetDirection() << std::endl;<br> <br> std::cout << "output from connectedThreshold->GetOutput()->GetDirection()" << std::endl;<br>
std::cout << connectedThreshold->GetOutput()->GetDirection() << std::endl;<br><br> std::cout << "output from caster->GetOutput()->GetDirection()" << std::endl;<br> std::cout << caster->GetOutput()->GetDirection() << 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<itk::Image<float, 3u>, itk::Image<float, 3u> > <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->GetOutput()->GetDirection()<br>0 0 1<br>0 1 0<br>-1 0 0<br>
<br>output from castFilter->GetOutput()->GetDirection()<br>0 0 1<br>0 1 0<br>-1 0 0<br><br>output from connectedThreshold->GetOutput()->GetDirection()<br>0 0 1<br>0 1 0<br>-1 0 0<br><br>output from caster->GetOutput()->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"><<a href="mailto:john.drozd@gmail.com">john.drozd@gmail.com</a>></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'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's paper: "Label object representation and manipulation with ITK"<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 "itkConnectedThresholdImageFilter.h"<br><br>#include "itkImage.h"<br>
#include "itkCastImageFilter.h"<br>
<br>#include "itkCurvatureFlowImageFilter.h"<br><br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br><br>#include "itkGDCMImageIO.h"<br><br>#include "itkVersion.h"<br>
<br>#include "itkOrientedImage.h"<br>#include "itkMinimumMaximumImageFilter.h"<br><br>#include "itkGDCMImageIO.h"<br>#include "itkGDCMSeriesFileNames.h"<br>#include "itkNumericSeriesFileNames.h"<br>
<br>#include "itkImageSeriesReader.h"<br>#include "itkImageSeriesWriter.h"<br><br>#include "itkResampleImageFilter.h"<br>#include "itkShiftScaleImageFilter.h"<br><br>#include "itkIdentityTransform.h"<br>
#include "itkLinearInterpolateImageFunction.h"<br><br>#include <itksys/SystemTools.hxx><br><br>#include "gdcm/src/gdcmFile.h"<br>#include "gdcm/src/gdcmUtil.h"<br><br>#include <string><br>
<br>//added per attribute_values.cxx<br>#include "itkImageFileReader.h"<br><br>#include "itkShapeLabelObject.h"<br>//#include "itkStatisticsLabelObject.h"<br><br>#include "itkLabelMap.h"<br>
<br>#include "itkBinaryImageToShapeLabelMapFilter.h"<br>//#include "itkBinaryImageToStatisticsLabelMapFilter.h"<br><br>//end of added code<br><br>int main( int argc, char *argv[])<br>{<br> if( argc < 7 )<br>
{<br> std::cerr << "Missing Parameters " << std::endl;<br> std::cerr << "Usage: " << argv[0];<br> std::cerr << " inputImage outputImage seedX seedY seedZ lowerThreshold upperThreshold" << std::endl;<br>
<br> return 1;<br> }<br><br> typedef float InternalPixelType;<br> <br> const unsigned int Dimension = 3;<br><br> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<br>
<br> typedef signed short OutputPixelType;<br><br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br> typedef itk::Image< float, Dimension > OutputImageType2;<br> typedef itk::CastImageFilter< InternalImageType, OutputImageType ><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< PixelType, ImageDimension > FixedImageType;<br>
typedef itk::Image< float, ImageDimension > FloatImageType;<br><br> typedef itk::ImageFileReader< FixedImageType > ReaderType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
typedef itk::ImageFileWriter< FloatImageType > 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->SetImageIO( gdcmImageIOfixed );<br><br> typedef itk::GDCMImageIO ImageIOTypefixed2;<br>
ImageIOTypefixed2::Pointer gdcmImageIOfixed2 = ImageIOTypefixed2::New();<br><br> reader->SetFileName( argv[1] );<br> <br> reader->Update();<br><br> typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType ><br>
CurvatureFlowImageFilterType;<br> <br> CurvatureFlowImageFilterType::Pointer smoothing =<br> CurvatureFlowImageFilterType::New();<br><br> typedef itk::ConnectedThresholdImageFilter< InternalImageType,<br>
InternalImageType > ConnectedFilterType;<br><br> ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();<br><br> typedef signed short InputAPixelType;<br> typedef float OutputBPixelType;<br>
<br> typedef itk::Image< InputAPixelType, 3 > InputAImageType;<br> typedef itk::Image< OutputBPixelType, 3 > OutputBImageType;<br><br> typedef itk::CastImageFilter< InputAImageType, OutputBImageType > CastFilterType;<br>
<br> CastFilterType::Pointer castFilter = CastFilterType::New();<br><br><br> castFilter->SetInput( reader->GetOutput() );<br> <br><br> connectedThreshold->SetInput( castFilter->GetOutput() );<br><br> caster->SetInput( connectedThreshold->GetOutput() );<br>
<br><br> smoothing->SetNumberOfIterations( 20 ); //was 5<br> smoothing->SetTimeStep( 0.125 );<br> <br> const InternalPixelType lowerThreshold = atof( argv[6] );<br> const InternalPixelType upperThreshold = atof( argv[7] );<br>
<br> connectedThreshold->SetLower( lowerThreshold );<br> connectedThreshold->SetUpper( upperThreshold );<br> <br> connectedThreshold->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 << index << std::endl;<br><br> // Software Guide : BeginCodeSnippet<br>
connectedThreshold->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 < ii + 5; i++)<br>
for (int j = jj; j < jj + 5; j++)<br> for (int k = kk; k < kk + 5; k++)<br> {<br> <br> index[0] = i;<br> index[1] = j;<br> index[2] = k;<br> connectedThreshold->AddSeed( index );<br>
}<br><br> for (int i = ii; i > ii - 5; i--)<br> for (int j = jj; j > jj - 5; j--)<br> for (int k = kk; k > kk - 5; k--)<br> {<br> <br> index[0] = i;<br> index[1] = j;<br> index[2] = k;<br>
connectedThreshold->AddSeed( index );<br> }<br><br> connectedThreshold->Print(std::cout,17100);<br> <br> typedef itk::MetaDataDictionary DictionaryType;<br> <br> DictionaryType inputdict = reader->GetMetaDataDictionary();<br>
<br> writer->SetMetaDataDictionary( inputdict );<br> <br> writer->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< LabelType, 3 > LabelObjectType;<br>
<br> typedef itk::LabelMap< LabelObjectType > LabelMapType;<br><br> // convert the image in a collection of objects<br> typedef itk::BinaryImageToLabelMapFilter< InternalImageType, LabelMapType > ConverterType;<br>
<br> ConverterType::Pointer converter = ConverterType::New();<br> <br> converter->SetInput( connectedThreshold->GetOutput() );<br><br> //converter->SetForegroundValue( atoi(argv[2]) );<br> //converter->SetForegroundValue( 255 );<br>
<br> // valuate the attributes with the dedicated filter: ShapeLabelMapFilter<br><br> typedef itk::ShapeLabelMapFilter< LabelMapType > ShapeFilterType;<br> ShapeFilterType::Pointer shape = ShapeFilterType::New();<br>
shape->SetInput( converter->GetOutput() );<br><br> shape->Update();<br><br><br> // then we can read the attribute values we'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->GetOutput();<br>
<br> std::cout << "Number of label objects = " << labelMap->GetNumberOfLabelObjects() << std::endl;<br><br><br> for( unsigned int label=1; label<=labelMap->GetNumberOfLabelObjects(); label++ )<br>
{<br> // we don'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->GetLabelObject( label );<br>
std::cout << label << "\t" << labelObject->GetPhysicalSize() << "\t" << labelObject->GetCentroid() << std::endl;<br> }<br><br> writer->SetInput( caster->GetOutput() );<br>
<br> try<br> {<br> writer->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception caught !" << std::endl;<br> std::cerr << excep << std::endl;<br>
}<br><br> std::cout << "output from reader->GetOutput()->GetDirection()" << std::endl;<br> std::cout << reader->GetOutput()->GetDirection() << std::endl;<br> <br> std::cout << "output from castFilter->GetOutput()->GetDirection()" << std::endl;<br>
std::cout << castFilter->GetOutput()->GetDirection() << std::endl;<br> <br> std::cout << "output from connectedThreshold->GetOutput()->GetDirection()" << std::endl;<br> std::cout << connectedThreshold->GetOutput()->GetDirection() << std::endl;<br>
<br> std::cout << "output from caster->GetOutput()->GetDirection()" << std::endl;<br> std::cout << caster->GetOutput()->GetDirection() << std::endl;<br><br> return 0;<br>}<br>
<br>
</blockquote></div><br>