"vscode:/vscode.git/clone" did not exist on "7e1d5e5308fa3549dfed1821188d588260a03c8a"
CPUStackResampler.h 3.18 KB
Newer Older
wangkx1's avatar
init  
wangkx1 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*! \file CPUStackResampler.h
    \brief Contains declaration of a class for spline/tri-linear resampling of irregularly sampled columns in the z-direction.

    \author Jesper Andersson
    \version 1.0b, May, 2021.
*/
//
// CPUStackResampler.h
//
// Jesper Andersson, FMRIB Image Analysis Group
//
// Copyright (C) 2021 University of Oxford
//

#ifndef CPUStackResampler_h
#define CPUStackResampler_h

#include <cstdlib>
#include <vector>
#include <armadillo>
#include "newimage/newimageall.h"
#include "EddyHelperClasses.h"

namespace EDDY {

class CPUStackResampler
{
public:
  /// Constructor. Performs the actual work so that when the object is created there is already a resampled image ready.

  /// This version of the constructor uses a predicted volume and the laplacian for regularisation
  CPUStackResampler(const NEWIMAGE::volume<float>&  stack,
		    const NEWIMAGE::volume<float>&  zcoord,
		    const NEWIMAGE::volume<float>&  pred,
		    const NEWIMAGE::volume<float>&  mask,
		    double                          lambda=0.005);

  /// This version of the constructor uses either splines and Laplacian regularisation or linear interpolation.
  CPUStackResampler(const NEWIMAGE::volume<float>&  stack,
		    const NEWIMAGE::volume<float>&  zcoord,
		    const NEWIMAGE::volume<float>&  mask,
		    NEWIMAGE::interpolation         interp=NEWIMAGE::spline,
		    double                          lambda=0.005);

  ~CPUStackResampler() {}

  // Returns interpolated image
  const NEWIMAGE::volume<float>& GetImage() const EddyTry { return(_ovol); } EddyCatch
  // Returns mask
  const NEWIMAGE::volume<float>& GetMask() const EddyTry { return(_omask); } EddyCatch

private:
  NEWIMAGE::volume<float> _ovol;
  NEWIMAGE::volume<float> _omask;
  void spline_interpolate_slice_stack(// Input
				      const NEWIMAGE::volume<float>&   slice_stack,
				      const NEWIMAGE::volume<float>&   z_coord,
				      const NEWIMAGE::volume<float>&   stack_mask,
				      double                           lambda,
				      // Optional input
				      const NEWIMAGE::volume<float>    *pred_ptr,
				      // Output
				      NEWIMAGE::volume<float>&         ovol,
				      NEWIMAGE::volume<float>&         omask);
  void linear_interpolate_slice_stack(// Input
				      const NEWIMAGE::volume<float>&   slice_stack,
				      const NEWIMAGE::volume<float>&   z_coord,
				      const NEWIMAGE::volume<float>&   stack_mask,
				      // Output
				      NEWIMAGE::volume<float>&         ovol,
				      NEWIMAGE::volume<float>&         omask);
  arma::Mat<float> get_StS(int sz, float lambda) const;
  arma::Mat<float> get_regular_W(int sz) const;
  arma::Mat<float> get_Wir(const NEWIMAGE::volume<float>& zcoord,
					    int i, int j) const;
  arma::Col<float> get_y(const NEWIMAGE::volume<float>& stack,
			 int i, int j) const EddyTry {
    arma::Col<float> y(stack.zsize());
    for (int k=0; k<stack.zsize(); k++) y[k] = stack(i,j,k);
    return(y);
  } EddyCatch
  float wgt_at(float x) const;
  std::vector<float> sort_zcoord(const NEWIMAGE::volume<float>& zcoord,
				 int i, int j) const;
  arma::Mat<float> get_prediction_weights(const std::vector<float> zcoord) const;
};

} // End namespace EDDY

#endif // End #ifndef CPUStackResampler_h