Developer documentation
Version 3.0.3-105-gd3941f44
initialiser_helpers.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __registration_transform_initialiser_helpers_h__
18#define __registration_transform_initialiser_helpers_h__
19
20#include <algorithm>
21#include <Eigen/Geometry>
22#include "image.h"
23#include "transform.h"
24#include "math/math.h"
25#include "math/SH.h"
28
29namespace MR
30{
31 namespace Registration
32 {
33 namespace Transform
34 {
35 namespace Init
36 {
37 template <class ImageType, class ValueType>
38 void get_geometric_centre (const ImageType& image, Eigen::Matrix<ValueType, 3, 1>& centre)
39 {
40 Eigen::Vector3d centre_voxel;
41 centre_voxel[0] = (static_cast<default_type>(image.size(0)) / 2.0) - 1.0;
42 centre_voxel[1] = (static_cast<default_type>(image.size(1)) / 2.0) - 1.0;
43 centre_voxel[2] = (static_cast<default_type>(image.size(2)) / 2.0) - 1.0;
44 MR::Transform transform (image);
45 centre = transform.voxel2scanner * centre_voxel;
46 }
47
50 Eigen::Vector3d& centre_of_mass,
51 const vector<MultiContrastSetting>& contrast_settings);
52
53 bool get_sorted_eigen_vecs_vals (const Eigen::Matrix<default_type, 3, 3>& mat,
54 Eigen::Matrix<default_type, Eigen::Dynamic, Eigen::Dynamic>& eigenvectors,
55 Eigen::Matrix<default_type, Eigen::Dynamic, 1>& eigenvals);
56
58 public:
60 Image<default_type>& image2,
64 ssize_t l_max = -1):
65 im1(image1),
66 im2(image2),
67 transform(transform),
68 mask1(mask1),
69 mask2(mask2),
70 lmax (l_max) {
71 assert (im1.ndim() == 4 && im2.ndim() == 4);
72 assert (im1.size(3) == im2.size(3));
73 ssize_t l = Math::SH::LforN(im1.size(3));
74 if (lmax == -1 or lmax > l) lmax = l;
75 N = Math::SH::NforL(lmax);
76 sh1.resize(N);
77 sh1.setZero();
78 sh2.resize(N);
79 sh2.setZero();
80 }
81
82 void run ();
83
84
85 protected:
88 Eigen::Matrix<default_type, Eigen::Dynamic, 1>& sh,
89 Eigen::Matrix<default_type, 3, 1>& centre_of_mass);
90
91 private:
97 ssize_t lmax, N;
98 Eigen::Matrix<default_type, 3, 1> im1_centre_of_mass, im2_centre_of_mass;
99 Eigen::Matrix<default_type, Eigen::Dynamic, 1> sh1, sh2;
100 };
101
103 public:
105 Image<default_type>& image2,
106 Image<default_type>& mask1,
107 Image<default_type>& mask2,
109 const vector<MultiContrastSetting>& contrast):
110 im1 (image1),
111 im2 (image2),
112 transform (transform),
113 mask1 (mask1),
114 mask2 (mask2),
115 contrast_settings (contrast) { }
116
117 void run ();
118
119
120 protected:
122 Image<default_type>& image_1,
123 Image<default_type>& image_2,
124 Image<default_type>& mask_1,
125 Image<default_type>& mask_2);
127
128 private:
132 Image<default_type>& mask1;
133 Image<default_type>& mask2;
134 const vector<MultiContrastSetting>& contrast_settings;
135 Eigen::Vector3d im1_centre, im2_centre;
136 Eigen::Matrix<default_type, 3, 1> im1_centre_of_mass, im2_centre_of_mass;
137 Eigen::Matrix<default_type, 3, 3> im1_covariance_matrix, im2_covariance_matrix;
138 Eigen::Matrix<default_type, Eigen::Dynamic, Eigen::Dynamic> im1_evec, im2_evec;
139 Eigen::Matrix<default_type, Eigen::Dynamic, 1> im1_eval, im2_eval;
140 };
141
142
143
144 }
145 }
146 }
147}
148
149#endif
size_t ndim() const
Definition: image.h:65
ssize_t size(size_t axis) const
Definition: image.h:66
void init(Image< default_type > &image, Image< default_type > &mask, Eigen::Matrix< default_type, Eigen::Dynamic, 1 > &sh, Eigen::Matrix< default_type, 3, 1 > &centre_of_mass)
bool calculate_eigenvectors(Image< default_type > &image_1, Image< default_type > &image_2, Image< default_type > &mask_1, Image< default_type > &mask_2)
const transform_type voxel2scanner
Definition: transform.h:43
size_t LforN(int N)
returns the largest lmax given N parameters
Definition: SH.h:70
size_t NforL(int lmax)
the number of (even-degree) coefficients for the given value of lmax
Definition: SH.h:46
bool get_sorted_eigen_vecs_vals(const Eigen::Matrix< default_type, 3, 3 > &mat, Eigen::Matrix< default_type, Eigen::Dynamic, Eigen::Dynamic > &eigenvectors, Eigen::Matrix< default_type, Eigen::Dynamic, 1 > &eigenvals)
void get_geometric_centre(const ImageType &image, Eigen::Matrix< ValueType, 3, 1 > &centre)
void get_centre_of_mass(Image< default_type > &im, Image< default_type > &mask, Eigen::Vector3d &centre_of_mass, const vector< MultiContrastSetting > &contrast_settings)
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228