newimage
 
Loading...
Searching...
No Matches
costfns.h
1/* costfns.h
2
3 Mark Jenkinson, FMRIB Image Analysis Group
4
5 Copyright (C) 2001 University of Oxford */
6
7/* CCOPYRIGHT */
8
9
10#if !defined(__costfns_h)
11#define __costfns_h
12
13#include "newimageall.h"
14
15namespace NEWIMAGE {
16
17 enum costfns { Woods, CorrRatio, MutualInfo, NormCorr, NormMI, LeastSq, LabelDiff,
18 NormCorrSinc, BBR, Unknown };
19
20 costfns costfn_type(const std::string& cname);
21
22 class Costfn {
23 public:
24 const volume<float> &refvol;
25 const volume<float> &testvol;
26 const volume<float> &rweight;
27 const volume<float> &tweight;
28 volume<float> wmseg; // WM segmentation (or any useful boundary) for BBR
29 volume<float> fmap; // fieldmap for BBR
30 volume<float> fmap_mask; // fieldmap mask for BBR
31 //volume4D<float> nonlin_basis;
32 mutable volume4D<float> debugvol;
33 NEWMAT::ColumnVector testCog;
34 private:
35 int *bindex;
36 int no_bins;
37 NEWMAT::ColumnVector plnp;
38 int *jointhist;
39 int *marghist1;
40 int *marghist2;
41 float *fjointhist;
42 float *fmarghist1;
43 float *fmarghist2;
44 mutable int p_count;
45 costfns p_costtype;
46 bool validweights;
47 float bin_a0;
48 float bin_a1;
49 float bbr_dist; // in mm
50 float bbr_offset;
51 float bbr_slope;
52 NEWMAT::Matrix bbr_pts; // in mm coords
53 NEWMAT::Matrix bbr_norms; // in mm coords pointing from wm to other
54 float *gm_coord_x; // in mm coords
55 float *gm_coord_y;
56 float *gm_coord_z;
57 float *wm_coord_x;
58 float *wm_coord_y;
59 float *wm_coord_z;
60 int no_coords;
61 int vertex_step;
62 int pe_dir; // for fieldmap application
63 std::string bbr_type;
64 bool debug_mode;
65 public:
66 float smoothsize;
67 float fuzzyfrac;
68
69 public:
70 // Publicly available calls
71 Costfn(const volume<float>& refv, const volume<float>& inputv);
72 Costfn(const volume<float>& refv, const volume<float>& inputv,
73 const volume<float>& refweight, const volume<float>& inweight);
74 ~Costfn();
75
76 void set_debug_mode(bool debug_flag=true);
77 void set_costfn(const costfns& costtype) { p_costtype = costtype; }
78 costfns get_costfn(void) { return p_costtype; }
79 void set_no_bins(int n_bins);
80 int set_bbr_seg(const volume<float>& bbr_seg);
81 int set_bbr_coords(const NEWMAT::Matrix& coords, const NEWMAT::Matrix& norms);
82 int set_bbr_type(const std::string& typenm);
83 int set_bbr_step(int step);
84 int set_bbr_slope(float slope);
85 int set_bbr_fmap(const volume<float>& fieldmap, int phase_encode_direction);
86 int set_bbr_fmap(const volume<float>& fieldmap, const volume<float>& fieldmap_mask, int phase_encode_direction);
87 int count() const { return p_count; }
88
89 // General cost function call
90 float cost(const NEWMAT::Matrix& affmat) const; // affmat is voxel to voxel
91 // affmat is voxel to voxel and non-linear parameters are arbitrary
92 float cost(const NEWMAT::Matrix& affmat, const NEWMAT::ColumnVector& nonlin_params) const;
93 // in the following, all warps are mm to mm
94 float cost(const volume4D<float>& warp) const;
95 float cost_gradient(volume4D<float>& gradvec,
96 const volume4D<float>& warp, bool nullbc) const;
97
98 // some basic entropy calls
99 float ref_entropy(const NEWMAT::Matrix& aff) const;
100 float test_entropy(const NEWMAT::Matrix& aff) const;
101 float joint_entropy(const NEWMAT::Matrix& aff) const;
102
103 volume<float> image_mapper(const NEWMAT::Matrix& affmat) const; // affmat is voxel to voxel
104 NEWMAT::Matrix mappingfn(const NEWMAT::Matrix& affmat) const; // affmat is voxel to voxel
105 float get_bin_intensity(int bin_number) const;
106 float get_bin_number(float intensity) const;
107 bool is_bbr_set(void) const;
108
109 // a resampling function (since it is logical to keep it with the general cost processing for bbr)
110 float bbr_resamp(const NEWMAT::Matrix& aff, const NEWMAT::ColumnVector& nonlin_params, volume<float>& resampvol) const;
111
112 private:
113 // Prevent default behaviours
114 Costfn();
115 Costfn operator=(const Costfn&);
116 Costfn(const Costfn&);
117
118 // Internal functions available
119 float normcorr(const NEWMAT::Matrix& aff) const;
120 float normcorr_smoothed(const NEWMAT::Matrix& aff) const;
121 float normcorr_smoothed_sinc(const NEWMAT::Matrix& aff) const;
122 float normcorr_fully_weighted(const NEWMAT::Matrix& aff,
123 const volume<float>& refweight,
124 const volume<float>& testweight) const;
125
126 float leastsquares(const NEWMAT::Matrix& aff) const;
127 float leastsquares_smoothed(const NEWMAT::Matrix& aff) const;
128 float leastsquares_fully_weighted(const NEWMAT::Matrix& aff,
129 const volume<float>& refweight,
130 const volume<float>& testweight) const;
131
132 float labeldiff(const NEWMAT::Matrix& aff) const;
133 float labeldiff_smoothed(const NEWMAT::Matrix& aff) const;
134 float labeldiff_fully_weighted(const NEWMAT::Matrix& aff,
135 const volume<float>& refweight,
136 const volume<float>& testweight) const;
137
138 float bbr(const NEWMAT::Matrix& aff) const;
139 float bbr(const NEWMAT::Matrix& aff, const NEWMAT::ColumnVector& nonlin_params) const;
140 float bbr(const NEWMAT::Matrix& aff, const NEWMAT::ColumnVector& nonlin_params,
141 volume<float>& resampvol, bool resampling_required) const;
142 float fmap_extrap(const double& x_vox, const double& y_vox, const double& z_vox, const NEWMAT::ColumnVector& v_pe) const;
143 int vox_coord_calc(NEWMAT::ColumnVector& tvc, NEWMAT::ColumnVector& rvc, const NEWMAT::Matrix& aff, const NEWMAT::ColumnVector& nonlin_params,
144 const NEWMAT::Matrix& iaffbig, const NEWMAT::Matrix& mm2vox, const NEWMAT::ColumnVector& pe_dir_vec) const;
145
146 float woods_fn(const NEWMAT::Matrix& aff) const;
147 float woods_fn_smoothed(const NEWMAT::Matrix& aff) const;
148
149 float corr_ratio(const NEWMAT::Matrix& aff) const;
150 float corr_ratio_smoothed(const NEWMAT::Matrix& aff) const;
151 float corr_ratio_fully_weighted(const NEWMAT::Matrix& aff,
152 const volume<float>& refweight,
153 const volume<float>& testweight) const;
154 float corr_ratio_fully_weighted(const volume4D<float>& warpvol,
155 const volume<float>& refweight,
156 const volume<float>& testweight) const;
157 float corr_ratio_gradient_fully_weighted(volume4D<float>& gradvec,
158 const volume4D<float>& warpvol,
159 const volume<float>& refweight,
160 const volume<float>& testweight,
161 bool nullbc) const;
162
163 float mutual_info(const NEWMAT::Matrix& aff) const;
164 float mutual_info_smoothed(const NEWMAT::Matrix& aff) const;
165 float mutual_info_fully_weighted(const NEWMAT::Matrix& aff,
166 const volume<float>& refweight,
167 const volume<float>& testweight) const;
168
169 float normalised_mutual_info(const NEWMAT::Matrix& aff) const;
170 float normalised_mutual_info_smoothed(const NEWMAT::Matrix& aff) const;
171 float normalised_mutual_info_fully_weighted(const NEWMAT::Matrix& aff,
172 const volume<float>& refweight,
173 const volume<float>& testweight) const;
174
175 float cost(const NEWMAT::Matrix& affmat,
176 const volume<float>& refweight,
177 const volume<float>& testweight) const;
178
179 float cost(const NEWMAT::Matrix& affmat,
180 const NEWMAT::ColumnVector& nonlin_params,
181 const volume<float>& refweight,
182 const volume<float>& testweight) const;
183
184 float cost(const volume4D<float>& warp,
185 const volume<float>& refweight,
186 const volume<float>& testweight) const;
187
188 float cost_gradient(volume4D<float>& gradvec,
189 const volume4D<float>& warp,
190 const volume<float>& refweight,
191 const volume<float>& testweight,
192 bool nullbc=false) const;
193
194 int p_corr_ratio_image_mapper(volume<float>& vout,
195 NEWMAT::Matrix& mappingfn,
196 const volume<float>& vref,
197 const volume<float>& vtest,
198 const volume<float>& refweight,
199 const volume<float>& testweight,
200 int *bindex, const NEWMAT::Matrix& aff,
201 const int no_bins, const float smoothsize) const;
202 };
203
204
206
207
208}
209
210#endif
Definition: costfns.h:22
Definition: newimage.h:100