ANIMA  4.0
animaNyulStandardization.cxx
Go to the documentation of this file.
1 #include <tclap/CmdLine.h>
2 
3 #include <itkHistogramMatchingImageFilter.h>
4 
7 
8 struct arguments
9 {
10  std::string reference, moving, output;
11  unsigned int nlevels, npoints, nthreads;
12 };
13 
14 template <class ComponentType, unsigned int InputDim>
15 void
16 standardize(itk::ImageIOBase::Pointer imageIO, const arguments &args)
17 {
18 
19  typedef itk::Image<ComponentType, InputDim> ImageType;
20  typedef itk::HistogramMatchingImageFilter<ImageType,ImageType> HistogramMatchingFilterType;
21 
22  typename HistogramMatchingFilterType::Pointer mainFilter = HistogramMatchingFilterType::New();
23  mainFilter->SetReferenceImage(anima::readImage<ImageType>(args.reference));
24  mainFilter->SetInput(anima::readImage<ImageType>(args.moving));
25  mainFilter->SetNumberOfHistogramLevels(args.nlevels);
26  mainFilter->SetNumberOfMatchPoints(args.npoints);
27  mainFilter->SetNumberOfWorkUnits(args.nthreads);
28  mainFilter->Update();
29 
30  anima::writeImage<ImageType>(args.output, mainFilter->GetOutput());
31 }
32 
33 template <class ComponentType>
34 void
35 retrieveNbDimensions(itk::ImageIOBase::Pointer imageIO, const arguments &args)
36 {
37  ANIMA_RETRIEVE_NUMBER_OF_DIMENSIONS(imageIO, ComponentType, standardize, imageIO, args)
38 }
39 
40 int main(int argc, char **argv)
41 {
42  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
43 
44  TCLAP::ValueArg<std::string> refArg("r","referencefile","Reference image",true,"","reference image",cmd);
45  TCLAP::ValueArg<std::string> movArg("m","movingfile","Moving image",true,"","moving image",cmd);
46  TCLAP::ValueArg<std::string> outArg("o","outputfile","output image",true,"","output image",cmd);
47 
48  TCLAP::ValueArg<unsigned int> nlvlArg("","nhl","Number of histogram levels (default: 100)",false,100,"number of histogram levels",cmd);
49  TCLAP::ValueArg<unsigned int> nptsArg("","nmp","Number of match points (default: 15)",false,15,"number of match points",cmd);
50 
51  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
52 
53  try
54  {
55  cmd.parse(argc,argv);
56  }
57  catch (TCLAP::ArgException& e)
58  {
59  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
60  return EXIT_FAILURE;
61  }
62 
63  // Find out the type of the image in file
64  itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(refArg.getValue().c_str(),itk::ImageIOFactory::ReadMode);
65 
66  if (!imageIO)
67  {
68  std::cerr << "Itk could not find a suitable IO factory for the input" << std::endl;
69  return EXIT_FAILURE;
70  }
71 
72  // Now that we found the appropriate ImageIO class, ask it to read the meta data from the image file.
73  imageIO->SetFileName(refArg.getValue());
74  imageIO->ReadImageInformation();
75 
76  arguments args;
77 
78  args.reference = refArg.getValue();
79  args.moving = movArg.getValue();
80  args.output = outArg.getValue();
81  args.nlevels = nlvlArg.getValue();
82  args.npoints = nptsArg.getValue();
83  args.nthreads = nbpArg.getValue();
84 
85  try
86  {
87  ANIMA_RETRIEVE_COMPONENT_TYPE(imageIO, retrieveNbDimensions, imageIO, args);
88  }
89  catch (itk::ExceptionObject &err)
90  {
91  std::cerr << err << std::endl;
92  return EXIT_FAILURE;
93  }
94 
95  return EXIT_SUCCESS;
96 }
std::string output
int main(int argc, char **argv)
itk::ImageIOBase::Pointer imageIO
void standardize(itk::ImageIOBase::Pointer imageIO, const arguments &args)
#define ANIMA_RETRIEVE_COMPONENT_TYPE(imageIO, function,...)
void retrieveNbDimensions(itk::ImageIOBase::Pointer imageIO, const arguments &args)
unsigned int nthreads
#define ANIMA_RETRIEVE_NUMBER_OF_DIMENSIONS(imageIO, ComponentType, function,...)