ANIMA  4.0
animaRemoveTouchingBorder.cxx
Go to the documentation of this file.
1 #include <tclap/CmdLine.h>
2 
3 #include <itkTimeProbe.h>
6 
7 int main(int argc, const char** argv)
8 {
9  const unsigned int Dimension = 3;
10  typedef itk::Image <unsigned char,Dimension> UCImageType;
11  typedef itk::Image <unsigned int,Dimension> UIImageType;
13 
14  // Parsing arguments
15  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
16 
17  // Setting up parameters
18 
19  // Input filenames
20  TCLAP::ValueArg<std::string> inArg("i","inputfile","Input image",true,"","input image",cmd);
21  TCLAP::ValueArg<std::string> outArg("o","outputfile","Output image",true,"","output image",cmd);
22 
23  TCLAP::ValueArg<std::string> maskFileArg("m","mask","Brain mask",true,"","brain mask",cmd);
24 
25  TCLAP::SwitchArg noContourDetectionArg("C","noContour","Avoid contour detection (default: false)",cmd,false);
26  TCLAP::SwitchArg rmNonTouchingArg("R","rmNonTouching","Remove non touching components instead of touching components (default: false)",cmd,false);
27  TCLAP::SwitchArg labeledImageArg("L","labeledImage","Input image is a labeled image (default: false)",cmd,false);
28 
29  // global
30  TCLAP::ValueArg<unsigned int> numThreadsArg("T","threads","Number of execution threads (default: 0 = all cores)",false,0,"number of threads",cmd);
31  TCLAP::SwitchArg verboseArg("v","verbose","verbose mode (default: false)",cmd,false);
32 
33  try
34  {
35  cmd.parse(argc,argv);
36  }
37  catch (TCLAP::ArgException& e)
38  {
39  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
40  return EXIT_FAILURE;
41  }
42 
43  FilterTypeSeg::Pointer segFilter = FilterTypeSeg::New();
44 
45  if(inArg.getValue() != "")
46  segFilter->SetInputImageSeg(anima::readImage<UIImageType> (inArg.getValue()));
47 
48  if(outArg.getValue() != "")
49  {
50  if(rmNonTouchingArg.isSet())
51  segFilter->SetOutputTouchingBorderFilename(outArg.getValue());
52  else
53  segFilter->SetOutputNonTouchingBorderFilename(outArg.getValue());
54  }
55 
56  if(maskFileArg.getValue() != "")
57  segFilter->SetMask(anima::readImage<UCImageType> (maskFileArg.getValue()));
58 
59  // Set parameters
60  segFilter->SetLabeledImage( labeledImageArg.getValue() );
61  segFilter->SetNoContour( noContourDetectionArg.getValue() );
62  segFilter->SetVerbose( verboseArg.getValue() );
63  segFilter->SetNumberOfWorkUnits( numThreadsArg.getValue() );
64 
65  // Process
66  itk::TimeProbe timer;
67 
68  std::cout << "Remove lesions touching border..." << std::endl;
69 
70  timer.Start();
71 
72  try
73  {
74  segFilter->Update();
75  segFilter->WriteOutputs();
76  }
77  catch (itk::ExceptionObject &e)
78  {
79  std::cerr << e << std::endl;
80  return EXIT_FAILURE;
81  }
82 
83  timer.Stop();
84 
85  std::cout << "Elapsed Time: " << timer.GetTotal() << timer.GetUnit() << std::endl;
86 
87  return EXIT_SUCCESS;
88 }
Class selecting the connected components touching a given mask border. In MRI, external CSF may conta...
int main(int argc, const char **argv)