// Author: Jonathan Brandvein // Copyright: disclaimed; derived from examples and not of substantial length #include #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkConnectedThresholdImageFilter.h" using namespace std; using namespace itk; int main (int argc, char* argv[]) { // Picture typedefs typedef unsigned short PixelType; const unsigned int Dimension = 3; typedef Image< PixelType, Dimension > ImageType; // IO typedef ImageFileReader< ImageType > ReaderType; typedef ImageFileWriter< ImageType > WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName("Normal100-T2.mha"); writer->SetFileName("Output.mhd"); // Threshold filter typedef ConnectedThresholdImageFilter< ImageType, ImageType > ConnectedFilterType; ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New(); // 250 seems to be a good lower boundary, at least for the upper part of the segmentation. // If I wanted to, I could've raised the lower threshold and added more seeds to try to get // a more precise segmentation, but I wasn't sure what the lower part of the ventricles were // supposed to look like. // The upper bound is supposed to be higher than the max intensity observed in the image. const int lower_threshold = 250; const int upper_threshold = 600; const Index<3> seed = {{205, 236, 86}}; connectedThreshold->AddSeed(seed); connectedThreshold->SetReplaceValue(100); connectedThreshold->SetLower(lower_threshold); connectedThreshold->SetUpper(upper_threshold); // Pipeline and execution connectedThreshold->SetInput(reader->GetOutput()); writer->SetInput(connectedThreshold->GetOutput()); try { writer->Update(); } catch (ExceptionObject& err) { cerr << "Exception:\n" << err << endl; return 1; } return 0; }