// @author T. Piekos // Confidence Connected Segmentation w/ITK // 10.18.2007 // code derived from sample code provided #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkImage.h" #include "itkConfidenceConnectedImageFilter.h" #include "itkCastImageFilter.h" using namespace std; using namespace itk; int main(int argc, char *argv[]) { if (argc < 6) { cerr << "Missing Parameters: [input file] [output file] [xseed] [yseed] [zseed]" << endl; return -1; } // define the image type typedef unsigned short InternalPixelType; const unsigned int Dimension = 3; typedef itk::Image< InternalPixelType, Dimension > InternalImageType; typedef unsigned short OutputPixelType; typedef itk::Image< OutputPixelType, Dimension > OutputImageType; typedef itk::ImageFileReader< InternalImageType > ReaderType; typedef itk::ImageFileWriter< OutputImageType > WriterType; // set up the reader ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); // set up the writer WriterType::Pointer writer = WriterType::New(); writer->SetFileName(argv[2]); typedef itk::ConfidenceConnectedImageFilter ConnectedFilterType; ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New(); // there was something with smoothing in the sample code, // removed confidenceConnected->SetInput( reader->GetOutput() ); writer->SetInput( confidenceConnected->GetOutput() ); confidenceConnected->SetMultiplier( 2.5 ); confidenceConnected->SetNumberOfIterations( 5 ); confidenceConnected->SetReplaceValue( 255 ); InternalImageType::IndexType index; index[0] = atoi( argv[3] ); index[1] = atoi( argv[4] ); // add a third dimension not in the sample code index[2] = atoi( argv[5] ); confidenceConnected->SetSeed( index ); confidenceConnected->SetInitialNeighborhoodRadius( 2 ); try { writer->Update(); } catch( itk::ExceptionObject & excep ) { cerr << "Exception caught !" << endl; cerr << excep << endl; } return 0; }