Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkKurtosisFitFunctor.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "itkKurtosisFitFunctor.h"
18 #include <iostream>
19 #include <iomanip>
20 
21 void itk::KurtosisFitFunctor::operator()(vnl_matrix<double> & newSignal, const vnl_matrix<double> & SignalMatrix, const double & S0)
22 {
23 
24  vnl_vector<double> initalGuess(2);
25  // initialize Least Squres Function
26  // SignalMatrix.cols() defines the number of shells points
27  lestSquaresFunction model(SignalMatrix.cols());
28  model.set_bvalues(m_BValueList);// set BValue Vector e.g.: [1000, 2000, 3000] <- shell b Values
29 
30  // initialize Levenberg Marquardt
31  vnl_levenberg_marquardt minimizer(model);
32  minimizer.set_max_function_evals(1000); // Iterations
33  minimizer.set_f_tolerance(1e-10); // Function tolerance
34 
35  // for each Direction calculate LSF Coeffs ADC & AKC
36  for(unsigned int i = 0 ; i < SignalMatrix.rows(); i++)
37  {
38  model.set_measurements(SignalMatrix.get_row(i));
39  model.set_reference_measurement(S0);
40 
41  initalGuess.put(0, 0.f); // ADC
42  initalGuess.put(1, 0.8f); // AKC
43 
44  // start Levenberg-Marquardt
45  minimizer.minimize_without_gradient(initalGuess);
46 
47  const double & ADC = initalGuess.get(0);
48  const double & AKC = initalGuess.get(1);
49 
50  newSignal.put(i, 0, S0 * std::exp(-m_TargetBvalue * ADC + 1./6. * m_TargetBvalue* m_TargetBvalue * ADC * ADC * AKC));
51  newSignal.put(i, 1, minimizer.get_end_error()); // RMS Error
52 
53  //OUTPUT FOR EVALUATION
54 
55  /*std::cout << std::scientific << std::setprecision(5)
56  << initalGuess[0] << "," // fitted ADC
57  << initalGuess[1] << "," // fitted AKC
58  << S0 << "," // S0 value
59  << minimizer.get_end_error() << ","; // End error
60  for(unsigned int j = 0; j < SignalMatrix.get_row(i).size(); j++ ){
61  std::cout << std::scientific << std::setprecision(5) << SignalMatrix.get_row(i)[j]; // S_n Values corresponding to shell 1 to shell n
62  if(j != SignalMatrix.get_row(i).size()-1) std::cout << ",";
63  }
64  std::cout << std::endl;*/
65  }
66 }
void operator()(vnl_matrix< double > &newSignal, const vnl_matrix< double > &SignalMatrix, const double &S0) override
operator ()
The lestSquaresFunction struct for Non-Linear-Least-Squres fit of Kurtosis.
vnl_vector< double > m_BValueList
void set_bvalues(const vnl_vector< double > &x)