Developer documentation
Version 3.0.3-105-gd3941f44
multi_resolution_lmax.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_multi_resolution_lmax_h__
18#define __registration_multi_resolution_lmax_h__
19
20#include "adapter/subset.h"
21#include "adapter/extract.h"
22#include "filter/smooth.h"
24
25namespace MR
26{
27 namespace Registration
28 {
29
30 template <class ImageType>
31 FORCE_INLINE ImageType multi_resolution_lmax (ImageType& input,
32 const default_type scale_factor,
33 const bool do_reorientation = false,
34 const uint32_t lmax = 0)
35 {
36 vector<uint32_t> from (input.ndim(), 0);
37 vector<uint32_t> size (input.ndim());
38 for (size_t dim = 0; dim < input.ndim(); ++dim)
39 size[dim] = input.size(dim);
40 if (do_reorientation)
41 size[3] = Math::SH::NforL (lmax);
42 Adapter::Subset<ImageType> subset (input, from, size);
43 Filter::Smooth smooth_filter (subset);
45 for (size_t dim = 0; dim < 3; ++dim)
46 stdev[dim] = input.spacing(dim) / (2.0 * scale_factor);
47
48 smooth_filter.set_stdev (stdev);
49 DEBUG ("creating scratch image for smoothing input image...");
50 auto smoothed = ImageType::scratch (smooth_filter);
51 threaded_copy (subset, smoothed);
52 DEBUG ("smoothing input image based on scale factor...");
53 smooth_filter (smoothed);
54 return smoothed;
55 }
56
57 // crop and resize images as defined in contrast: contrast[tissue].start is relative to input,
58 // contrast_updated[tissue].start is relative to cropped image. contrast and contrast_updated can be identical
59 template <class ImageType>
60 FORCE_INLINE ImageType multi_resolution_lmax (ImageType& input,
61 const default_type scale_factor,
62 const bool do_reorientation,
63 const vector<MultiContrastSetting>& contrast,
64 vector<MultiContrastSetting>* contrast_updated = nullptr)
65 {
66 vector<uint32_t> volume_indices;
67 size_t start = 0;
68 for (size_t ic = 0; ic < contrast.size(); ic++) {
69 const auto & mc = contrast[ic];
70 assert (mc.nvols > 0);
71 for (size_t i = 0; i < mc.nvols; i++)
72 volume_indices.push_back(mc.start + i);
73 // adjust start index to be relative to subset
74 if (contrast_updated)
75 (*contrast_updated)[ic].start = start;
76 start += mc.nvols;
77 }
78 Adapter::Extract1D<ImageType> subset (input, 3, volume_indices);
79
80 Filter::Smooth smooth_filter (subset);
82 for (size_t dim = 0; dim < 3; ++dim)
83 stdev[dim] = input.spacing(dim) / (2.0 * scale_factor);
84
85 smooth_filter.set_stdev (stdev);
86 DEBUG ("creating scratch image for smoothing input image...");
87 auto smoothed = ImageType::scratch (smooth_filter);
88 threaded_copy (subset, smoothed);
89 DEBUG ("smoothing input image based on scale factor...");
90 smooth_filter (smoothed);
91 return smoothed;
92 }
93 }
94}
95#endif
#define DEBUG(msg)
Definition: exception.h:75
matrix_type stdev(const matrix_type &measurements, const matrix_type &design)
size_t NforL(int lmax)
the number of (even-degree) coefficients for the given value of lmax
Definition: SH.h:46
FORCE_INLINE ImageType multi_resolution_lmax(ImageType &input, const default_type scale_factor, const bool do_reorientation=false, const uint32_t lmax=0)
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
void threaded_copy(InputImageType &source, OutputImageType &destination, const vector< size_t > &axes, size_t num_axes_in_thread=1)
Definition: threaded_copy.h:43
#define FORCE_INLINE
Definition: types.h:156