36 template <
typename A,
typename B>
37 void __assert_type_equal (A& a, B& b)
39 static_assert(
sizeof(A) == 0);
43 void __assert_type_equal (A& , A& )
47 #define ASSERT_TYPE_EQUAL(A, B) \ 50 __assert_type_equal(a,b); \ 53 template <
template <
typename>
class Data,
typename T>
55 static Data<float> *apply(
const Data<T> &
input,
double m,
double v) {
56 Data<float> *result =
new Data<float>(input.get_size());
58 transform(input.begin(), input.end(), result->begin(),
59 [invv,m](T x){(x - m) * invv;});
65 template <
template <
typename>
class Data>
66 struct __eval<Data, bool> {
67 static Data<float> *apply(
const Data<bool> &input,
double m,
double v) {
69 Data<float> *result =
new Data<float>(input.get_size());
70 float rtrue = (1.0 - m) / v;
71 float rfalse = - m / v;
73 transform(input.begin(), input.end(), result->begin(),
74 [rtrue, rfalse](
bool x){b ? rtrue : rfalse;});
89 template <
class Image>
90 struct FNormalizer:
public TFilter<Image *>
92 template <
typename T,
template <
typename>
class Data>
93 typename FNormalizer::result_type operator ()(
const Data<T> &image)
const {
94 ASSERT_TYPE_EQUAL(Image,
typename Data<T>::Super);
97 typename Data<T>::const_iterator i = image.begin();
98 typename Data<T>::const_iterator e = image.end();
104 double n = image.size();
106 double v = sqrt((sum2 - n * m * m) / (n - 1));
108 mia::cvdebug() <<
"FNormalizer: avg = " << m <<
" var = " << v <<
"\n";
113 return __eval<Data, T>::apply(image, m, v);
130 template <
class Image>
133 FNormalizer<Image> n;
134 return std::shared_ptr<Image >(
mia::filter(n, image));
base class for all filer type functors.
std::shared_ptr< Image > normalize(const Image &image)
a normalizer for image intensities
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
static F::result_type filter(const F &f, const B &b)
#define NS_MIA_END
conveniance define to end the mia namespace