18#ifndef __registration_metric_cc_helper_h__
19#define __registration_metric_cc_helper_h__
28 namespace Registration
33 template <
class Im1ImageType,
class Im2ImageType,
class Im1MaskType,
class Im2MaskType,
class DerivedImageType>
35 Im2ImageType& im2_image,
36 Im1MaskType& im1_mask,
37 Im2MaskType& im2_mask,
41 DerivedImageType& im1_meansubtr,
42 DerivedImageType& im2_meansubtr,
45 int nmax = extent[0] * extent[1] * extent[2];
46 Eigen::VectorXd n1 = Eigen::VectorXd(nmax);
47 Eigen::VectorXd n2 = Eigen::VectorXd(nmax);
49 for (
auto l =
Loop(
"precomputing cross correlation values") (im1_image); l; ++l) {
50 pos[0] = im1_image.index(0);
51 pos[1] = im1_image.index(1);
52 pos[2] = im1_image.index(2);
53 assign_pos_of(im1_image, 0, 3).to(A, B, C, im1_meansubtr, im2_meansubtr);
62 while (niter.loop()) {
63 if (im1_mask.valid()) {
64 assign_pos_of(niter, 0, 3).to(im1_mask);
65 if (!im1_mask.value())
68 if (im2_mask.valid()) {
69 assign_pos_of(niter, 0, 3).to(im2_mask);
70 if (!im2_mask.value())
73 assign_pos_of(niter, 0, 3).to(im1_image);
74 assign_pos_of(niter, 0, 3).to(im2_image);
76 n1[nvox] = im1_image.value();
77 n2[nvox] = im2_image.value();
88 im1_meansubtr.value() =
NaN;
89 im2_meansubtr.value() =
NaN;
94 n1.array() -= n1.sum() / nvox;
95 n2.array() -= n2.sum() / nvox;
96 A.value() = n1.adjoint() * n2;
97 B.value() = n1.adjoint() * n1;
98 C.value() = n2.adjoint() * n2;
101 im1_image.index(0) = pos[0];
102 im1_image.index(1) = pos[1];
103 im1_image.index(2) = pos[2];
105 im2_image.index(0) = pos[0];
106 im2_image.index(1) = pos[1];
107 im2_image.index(2) = pos[2];
109 im1_meansubtr.value() = im1_image.value() - m1 / nvox;
110 im2_meansubtr.value() = im2_image.value() - m2 / nvox;
a dummy image to iterate over a certain neighbourhood, useful for multi-threaded looping.
FORCE_INLINE LoopAlongAxes Loop()
void cc_precompute(Im1ImageType &im1_image, Im2ImageType &im2_image, Im1MaskType &im1_mask, Im2MaskType &im2_mask, DerivedImageType &A, DerivedImageType &B, DerivedImageType &C, DerivedImageType &im1_meansubtr, DerivedImageType &im2_meansubtr, const vector< size_t > &extent)
double default_type
the default type used throughout MRtrix
constexpr default_type NaN