17#ifndef __dwi_noise_estimator_h__
18#define __dwi_noise_estimator_h__
32 template <
class InputImageType,
class OutputImageType,
class MatrixType>
33 class NoiseEstimatorFunctor {
MEMALIGN(NoiseEstimatorFunctor<InputImageType,OutputImageType,MatrixType>)
36 NoiseEstimatorFunctor (
const MatrixType& SH2amp_mapping,
int axis, InputImageType&
dwi, OutputImageType&
noise) :
39 H (SH2amp_mapping * Math::
pinv (SH2amp_mapping)),
41 R (
S.cols(),
S.rows()),
44 for (ssize_t n = 0; n <
leverage.size(); ++n)
45 leverage[n] =
H(n,n) < 1.0 ? 1.0 / std::sqrt (1.0 -
H(n,n)) : 1.0;
48 void operator () (
const Iterator& pos) {
51 for (
auto l2 =
Loop (3) (
dwi); l2; ++l2)
54 R.noalias() =
H.selfadjointView<Eigen::Lower>() *
S -
S;
65 Eigen::MatrixXd
H,
S,
R;
75 template <
class InputImageType,
class OutputImageType,
class MatrixType>
78 NoiseEstimatorFunctor<InputImageType,OutputImageType,MatrixType>
functor (SH2amp_mapping, loop.inner_axes[0],
dwi,
noise);
FORCE_INLINE LoopAlongAxes Loop()
Eigen::Matrix< typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic > pinv(const MatrixType &M)
return Moore-Penrose pseudo-inverse of M
void estimate_noise(InputImageType &dwi, OutputImageType &noise, const MatrixType &SH2amp_mapping)
ThreadedLoopRunOuter< decltype(Loop(vector< size_t >()))> ThreadedLoop(const HeaderType &source, const vector< size_t > &outer_axes, const vector< size_t > &inner_axes)
Multi-threaded loop object.
Math::Sn_scale_estimator< default_type > scale_estimator
std::remove_reference< Functor >::type & functor