Hi Richard,<br><br>I don't know if you have time to help me, but I thought I would ask you anyways.<br>If you can't help me, that's ok.<br><br>As you suggested, I am trying to get a label map using itkBinaryImageToShapeLabelMapFilter, <br>
but I am getting zero label objects and I don't know why.<br><br>In my code below, I perform a connected threshold filter segmentation, then after some casting, I feed the segmentation<br>to an itkBinaryImageToLabelMapFilter, which is then fed to a itkLabelMapToLabelImageFilter, and finally to<br>
the itkBinaryImageToShapeLabelMapFilter.<br><br>Using the deprecated itkRelabelComponentImageFilter, I do get labeled objects, but I would like to get my code working using the itkBinaryImageToShapeLabelMapFilter.<br><br>
Can you see what I am doing wrong?<br><br>My output is below (the first four outputted lines are from the deprecated itkRelabelComponentImageFilter):<div class="im"><br><br>./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103 142 95 17100 17300<br>
</div><div class="im">
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></div>labelMap->GetNumberOfLabelObjects() = 0<br><br><br>My code is below.<div>
<div><span id="q_125751924150cfb6_4" class="h4">- Show quoted text -</span></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 "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><br></div></div><div class="im">#include "itkLabelMap.h"<br><br>#include "itkBinaryImageToShapeLabelMapFilter.h"<br></div>//end of added code<div class="im">
<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" target="_blank">http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html</a><br>
</div><div class="im">
#include "itkConnectedComponentImageFilter.h"<br>#include "itkRelabelComponentImageFilter.h"<br>//END OF ADDED CODE<br><br><br></div>//added per statistics_relabel.cxx<br>#include "itkStatisticsRelabelImageFilter.h"<br>
//end of added code<br><br>//added per label.cxx<br>#include "itkLabelObject.h"<br>#include "itkLabelMap.h"<br>#include "itkBinaryImageToLabelMapFilter.h"<br>#include "itkLabelMapToLabelImageFilter.h"<div>
<div><span id="q_125751924150cfb6_10" class="h4">- Show quoted text -</span></div><div class="h5"><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></div></div><div class="im"> // 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></div><div class="im"> typedef itk::MetaDataDictionary DictionaryType;<br> <br> DictionaryType inputdict = reader->GetMetaDataDictionary();<br>
<br> writer->SetMetaDataDictionary( inputdict );<br> <br> writer->SetFileName( argv[2] );<br><br> <br><br></div> //ADDED PER WEB PAGE: This deprecated code works<div class="im"><br> //<a href="http://old.nabble.com/Labeling-an-image-and-displaying-results-with-distinguished-levels-of-gray-colors-td26623991.html" target="_blank">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></div> /***************************************************************************/<br>
//but the code below fails to label the binary image giving zero label objects<br> /***************************************************************************/<br><br> typedef itk::Image < signed short, 3 > IType;<br>
<br> typedef itk::LabelObject< signed short, 3 > LabelObjectTypeD;<br> typedef itk::LabelMap< LabelObjectTypeD > LabelMapTypeD;<br> <br> typedef itk::BinaryImageToLabelMapFilter< OutputImageType, LabelMapTypeD> I2LType;<br>
I2LType::Pointer i2l = I2LType::New();<br> i2l->SetInput( caster->GetOutput() );<br> i2l->SetFullyConnected( 255 );<br> //i2l->SetForegroundValue( 100 );<br> //i2l->SetBackgroundValue( 255 );<br> //i2l->Update();<br>
i2l->GetOutput()->PrintLabelObjects();<br> typedef itk::LabelMapToLabelImageFilter< LabelMapTypeD, IType> L2IType;<br> L2IType::Pointer l2i = L2IType::New();<br> l2i->SetInput( i2l->GetOutput() );<br>
<br> typedef signed short LabelType3;<br> typedef itk::ShapeLabelObject< LabelType3, 3 > LabelObjectType2;<br> typedef itk::LabelMap< LabelObjectType2 > LabelMapType2;<br><br> typedef itk::BinaryImageToShapeLabelMapFilter< IType, LabelMapType2 > ConverterType;<div class="im">
<br>
ConverterType::Pointer converter = ConverterType::New();<br></div> converter->SetInput( l2i->GetOutput() );<br> <br> <br> LabelMapType2::Pointer labelMap = converter->GetOutput();<br><br> std::cout << "labelMap->GetNumberOfLabelObjects() = " << labelMap->GetNumberOfLabelObjects() << std::endl;<div class="im">
<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></div> return 0;<br>}<br><br>Thanks,<br><font color="#888888">john</font>