ANIMA  4.0
animaDisplacementFieldJacobian.cxx
Go to the documentation of this file.
1 #include <tclap/CmdLine.h>
2 
5 #include <animaVelocityUtils.h>
6 
7 int main(int ac, const char** av)
8 {
9  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ', ANIMA_VERSION);
10 
11  TCLAP::ValueArg<std::string> inArg("i","input","Input field",true,"","input image",cmd);
12  TCLAP::ValueArg<std::string> outArg("o","output","Output jacobian image",true,"","output image",cmd);
13 
14  TCLAP::ValueArg<unsigned int> neighArg("n","neigh","Neighborhood size for Jacobian computation (default: 0 = 6-connectivity)",false,0,"neighborhood size",cmd);
15 
16  TCLAP::SwitchArg svfArg("S","svf","Compute the exponential of the input SVF",cmd,false);
17  TCLAP::ValueArg<unsigned int> expOrderArg("e","exp-order","Order of field exponentiation approximation (in between 0 and 1, default: 0)",false,0,"exponentiation order",cmd);
18  TCLAP::SwitchArg noIdArg("N","no-id","Do not add identity to the jacobian matrix",cmd,false);
19  TCLAP::SwitchArg detArg("D","det","Simply compute the determinant of the jacobian (-N option ignored in that case)",cmd,false);
20  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
21 
22  try
23  {
24  cmd.parse(ac,av);
25  }
26  catch (TCLAP::ArgException& e)
27  {
28  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
29  return EXIT_FAILURE;
30  }
31 
32  const unsigned int Dimension = 3;
33  typedef double PixelType;
34 
35  typedef itk::Image <itk::Vector <PixelType, Dimension>, Dimension> ImageType;
36 
37  ImageType::Pointer inputField = anima::readImage <ImageType> (inArg.getValue());
38 
39  if (svfArg.isSet())
40  {
41  typedef itk::StationaryVelocityFieldTransform <PixelType, Dimension> SVFType;
42  SVFType::Pointer svfTrsf = SVFType::New();
43  svfTrsf->SetParametersAsVectorField(inputField);
44 
45  typedef rpi::DisplacementFieldTransform <PixelType, Dimension> RPIDispType;
46  RPIDispType::Pointer resTrsf = RPIDispType::New();
47 
48  anima::GetSVFExponential(svfTrsf.GetPointer(),resTrsf.GetPointer(),expOrderArg.getValue(),nbpArg.getValue(),false);
49 
50  inputField = const_cast <ImageType *> (resTrsf->GetParametersAsVectorField());
51  }
52 
54  MainFilterType::Pointer mainFilter = MainFilterType::New();
55 
56  mainFilter->SetInput(inputField);
57  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
58  mainFilter->SetNeighborhood(neighArg.getValue());
59  mainFilter->SetNoIdentity(noIdArg.isSet());
60  mainFilter->SetComputeDeterminant(detArg.isSet());
61 
62  mainFilter->Update();
63 
64  if (detArg.isSet())
65  anima::writeImage <MainFilterType::DeterminantImageType> (outArg.getValue(),mainFilter->GetDeterminantImage());
66  else
67  anima::writeImage <MainFilterType::OutputImageType> (outArg.getValue(),mainFilter->GetOutput());
68 
69  return EXIT_SUCCESS;
70 }
Compute the Jacobian matrix in real coordinates of a displacement field.
void GetSVFExponential(itk::StationaryVelocityFieldTransform< ScalarType, NDimensions > *baseTrsf, rpi::DisplacementFieldTransform< ScalarType, NDimensions > *resultTransform, unsigned int exponentiationOrder, unsigned int numThreads, bool invert)
int main(int ac, const char **av)