-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.h
73 lines (53 loc) · 1.47 KB
/
utilities.h
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
#ifndef _UTILITIES_H_
#define _UTILITIES_H_
#include <vector>
#include <assert.h>
namespace imageRegistration
{
template <class T>
T mean(const std::vector<T> & v)
{
class std::vector<T>::const_iterator it = v.begin();
T m(0);
for(; it != v.end(); ++it)
m = m + *it;
return m/v.size();
}
template <class T>
T coVar(const std::vector<T> & v, const std::vector<T> & w)
{
size_t sv = v.size();
assert(sv == w.size());
T cV(0);
for(size_t it = 0; it < sv; ++it)
cV = cV + v[it] * w[it];
cV = cV / sv;
cV = cV - mean(v) * mean(w);
return cV;
}
template <class T>
double corr(const std::vector<T> & v, const std::vector<T> & w)
{
size_t sv = v.size();
assert(sv == w.size());
double corr = coVar(v, w);
corr /= pow(coVar(v) * coVar(w), 1/2);
return corr;
}
/// Insert tr_ at the beginning of a filename, even if given by full path. (Slash delimited.)
std::string transformString(const std::string & s_, const char * tr_ = "tr_");
template <class T>
double absAverageDiff(const T & t0, const T & t1)
{
assert(t0.size() == t1.size());
typename T::const_iterator it0(t0.begin());
typename T::const_iterator it1(t1.begin());
double sum(0);
for(; it0 != t0.end(); ++it0)
sum += absAverageDiff(*it0, *it1);
return sum/t0.size();
}
double absAverageDiff(const double & t0, const double & t1);
double absAverageDiff(const drgb & t0, const drgb & t1);
} //namespace imageRegistration
#endif // _UTILITIES_H_