Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkADCAverageFunctor.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 "itkADCAverageFunctor.h"
18 #include <math.h>
19 #include <iostream>
20 #include <iomanip>
21 
22 void itk::ADCAverageFunctor::operator()(vnl_matrix<double> & newSignal, const vnl_matrix<double> & SignalMatrix, const double & S0)
23 {
24 
25  vnl_matrix<double> ADCMatrix(SignalMatrix.rows(),SignalMatrix.cols());
26 
27  // Calculate ADC for each measurement
28  for(unsigned int i = 0 ; i < SignalMatrix.rows(); ++i)
29  for(unsigned int j = 0; j < SignalMatrix.cols(); ++j)
30  ADCMatrix(i,j) = std::log(SignalMatrix(i,j) / S0) / (-m_BValueList[j]);// D = ln(S/S0)/-b
31 
32 
33  // Calculate new Signal using Average ADC
34  for(unsigned int i = 0 ; i < SignalMatrix.rows(); ++i){
35  double averageADC = ADCMatrix.get_row(i).mean();
36  newSignal.put(i,0, S0 * std::exp(-m_TargetBvalue * averageADC) ); // S = S0*exp(-b*D)
37 
38  //OUTPUT FOR EVALUATION
39  // Root Mean Squares Error
40  double error = 0;
41  for(unsigned int j = 0 ; j < SignalMatrix.cols(); ++j)
42  error += std::pow(SignalMatrix(i,j) - S0 * std::exp(-m_BValueList[j] * averageADC),2); // sum of squres
43  error /= (double)SignalMatrix.cols(); // mean
44  error = std::sqrt(error);
45 
46  newSignal.put(i, 1, error ); // RMS Error
47 
48  /*std::cout << std::scientific << std::setprecision(5)
49  << averageADC << "," // AverageADC
50  << S0 << "," // S0 value
51  << error << ","; // End error
52  for(unsigned int j = 0; j < SignalMatrix.get_row(i).size(); j++ )
53  std::cout << std::scientific << std::setprecision(5) << SignalMatrix.get_row(i)[j] << ","; // S_n Values corresponding to shell 1 to shell n
54  std::cout << std::endl;*/
55  }
56 }
vnl_vector< double > m_BValueList
void operator()(vnl_matrix< double > &newSignal, const vnl_matrix< double > &SignalMatrix, const double &S0) override
operator ()