// Software Guide : BeginLatex // // The following code is an implementation of a small Insight // program. It tests including header files and linking with ITK // libraries. // // Software Guide : EndLatex // Software Guide : BeginCodeSnippet #include "itkImage.h" #include #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkConnectedThresholdImageFilter.h" int main() { typedef short PixelType; const unsigned int Dimension = 3; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImageFileReader< ImageType > ReaderType; typedef itk::ImageFileWriter< ImageType > WriterType; typedef itk::ConnectedThresholdImageFilter< ImageType, ImageType > ConnectedFilterType; ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New(); itk::Index<3> index = {{ 100, 119, 69 }}; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName( "Normal066-T2.mhd" ); writer->SetFileName( "Segment066.mhd" ); connectedThreshold->SetInput( reader->GetOutput() ); writer->SetInput( connectedThreshold->GetOutput() ); connectedThreshold->SetLower( 2000 ); connectedThreshold->SetUpper( 2300 ); connectedThreshold->SetReplaceValue( 255 ); connectedThreshold->SetSeed( index ); try { writer->Update(); } catch( itk::ExceptionObject & excep ) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << excep << std::endl; return EXIT_FAILURE; } return 0; } // Software Guide : EndCodeSnippet // Software Guide : BeginLatex // // This code instantiates a $3D$ image\footnote{Also known as a // \emph{volume}.} whose pixels are represented with type \code{unsigned // short}. The image is then constructed and assigned to a // \doxygen{SmartPointer}. Although later in the text we will discuss // \code{SmartPointer}'s in detail, for now think of it as a handle on an // instance of an object (see section \ref{sec:SmartPointers} for more // information). The \doxygen{Image} class will be described in // Section~\ref{sec:ImageSection}. // // Software Guide : EndLatex