Hi,<br><br>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.<br><br>Thanks,<br>john<br><br><div class="gmail_quote">On Fri, Dec 11, 2009 at 1:58 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 Luis, Richard and Bonjour Gaetan, <br><br>Thank you all for helping me. My code works now giving me the correct output:<br>
<br>[jdrozd@trumpet ConnectedThresholdImageFilter_and_BinaryImageToStatisticsLabelMapFilter]$ ./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm 103 142 95 17100 17300<br>
labelMap->GetNumberOfLabelObjects() = 1<br>1 23901.3 [294.881, 123.841, -97.2387]<br><br> Below is my code to complete the communication thread (and thanks again):<div><div></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><div class="im">
//end of added code<br><br>//added per label.cxx<br></div>#include "itkLabelObject.h"<br>#include "itkLabelMap.h"<br>#include "itkBinaryImageToLabelMapFilter.h"<br>#include "itkLabelMapToLabelImageFilter.h"<br>
//end of added code<br><br>#include "itkSimpleFilterWatcher.h"<div class="im"><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></div> typedef unsigned char BinaryPixelType;<div class="im"><br><br> const unsigned int Dimension = 3;<br><br></div> typedef itk::Image< BinaryPixelType, Dimension > BinaryImageType;<br> <br>
<br> typedef signed short InputPixelType;<br>
<br> typedef itk::Image< InputPixelType, Dimension > InputImageType;<br> typedef unsigned char LabelType;<br> const unsigned int dim = 3;<br> typedef itk::ShapeLabelObject< LabelType, dim > LabelObjectType;<div class="im">
<br>
typedef itk::LabelMap< LabelObjectType > LabelMapType;<br></div> typedef itk::BinaryImageToShapeLabelMapFilter< BinaryImageType, LabelMapType> ConverterType;<div class="im"><br><br> ConverterType::Pointer converter = ConverterType::New();<br>
<br></div> typedef itk::ImageFileReader< InputImageType > ReaderType;<br> typedef itk::ImageFileWriter< BinaryImageType > WriterType;<div class="im"><br> <br> ReaderType::Pointer reader = ReaderType::New();<br>
WriterType::Pointer writer = WriterType::New();<br>
<br></div><div class="im"> 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></div> typedef itk::ConnectedThresholdImageFilter< InputImageType,<br>
BinaryImageType > ConnectedFilterType;<div class="im"><br><br> ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();<br> <br></div> connectedThreshold->SetInput( reader->GetOutput() );<br>
<br> const InputPixelType lowerThreshold = atof( argv[6] );<br> const InputPixelType upperThreshold = atof( argv[7] );<div class="im"><br><br> connectedThreshold->SetLower( lowerThreshold );<br> connectedThreshold->SetUpper( upperThreshold );<br>
<br> connectedThreshold->SetReplaceValue( 255 );<br><br></div> BinaryImageType::IndexType index;<div class="im"><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 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></div> connectedThreshold->Update();<br><br> converter->SetInput( connectedThreshold->GetOutput() );<br>
<br> converter->SetFullyConnected( true );<br>
<br> converter->SetInputForegroundValue( 255 );<br><br> converter->SetOutputBackgroundValue( 0 );<br><br> converter->Update();<br><br> LabelMapType::Pointer labelMap = converter->GetOutput();<br><br> std::cout << "labelMap->GetNumberOfLabelObjects() = " << labelMap->GetNumberOfLabelObjects() << std::endl;<div class="im">
<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></div> typedef itk::LabelMapToLabelImageFilter< LabelMapType, BinaryImageType > L2IType;<div class="im"><br><br> L2IType::Pointer l2i = L2IType::New();<br> <br></div> l2i->SetInput( converter->GetOutput() );<br>
<br> writer->SetInput( l2i->GetOutput() );<div class="im"><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;<div><div></div><div class="h5"><br>}<br><br><br><br><br></div></div></blockquote></div><br>