ANIMA  4.0
animaT2RelaxometryCostFunction.cxx
Go to the documentation of this file.
2 
3 namespace anima
4 {
5 
8 {
9  m_T2Value = parameters[0];
10 
11  double residualValue = 0;
12  unsigned int numT2Signals = m_T2RelaxometrySignals.size();
13 
14  std::vector <double> simulatedT2Values(numT2Signals,0.0);
15 
16  for(unsigned int i = 0;i < numT2Signals;++i)
17  {
18  double echo = (i + 1) * m_T2EchoSpacing;
19  simulatedT2Values[i] = std::exp(- echo / m_T2Value) / (1.0 - std::exp(- m_TRValue / m_T1Value));
20  }
21 
22  double sumSignals = 0;
23  double sumSimulatedSignals = 0;
24  for (unsigned int i = 0;i < numT2Signals;++i)
25  {
26  sumSignals += m_T2RelaxometrySignals[i];
27  sumSimulatedSignals += simulatedT2Values[i];
28  }
29 
30  m_M0Value = sumSignals / sumSimulatedSignals;
31 
32  for (unsigned int i = 0;i < numT2Signals;++i)
33  residualValue += (m_M0Value * simulatedT2Values[i] - m_T2RelaxometrySignals[i]) * (m_M0Value * simulatedT2Values[i] - m_T2RelaxometrySignals[i]);
34 
35  return residualValue;
36 }
37 
38 } // end namespace anima
virtual MeasureType GetValue(const ParametersType &parameters) const ITK_OVERRIDE