8 #ifndef META_OCEAN_CV_FRAME_NORM_H
9 #define META_OCEAN_CV_FRAME_NORM_H
39 template <
typename T,
typename TNorm>
40 static TNorm normL2(
const T* data,
const size_t size);
54 template <
typename T,
typename TNorm>
55 static TNorm normL2(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements);
66 template <
typename T,
typename TNorm>
67 static TNorm squaredNormL2(
const T* data,
const size_t size);
80 template <
typename T,
typename TNorm>
81 static TNorm squaredNormL2(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements);
84 template <
typename T,
typename TNorm>
87 ocean_assert(data !=
nullptr);
88 ocean_assert(size != 0);
93 template <
typename T,
typename TNorm>
94 TNorm
FrameNorm::normL2(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements)
96 ocean_assert(frame !=
nullptr);
97 ocean_assert(width != 0u && height != 0u);
102 template <
typename T,
typename TNorm>
105 ocean_assert(data !=
nullptr);
106 ocean_assert(size != 0);
112 TNorm result0 = TNorm(0);
113 TNorm result1 = TNorm(0);
114 TNorm result2 = TNorm(0);
115 TNorm result3 = TNorm(0);
121 for (n = 0; n < ptrdiff_t(size) - 3; n += 4)
123 result0 += TNorm(data[n + 0] * data[n + 0]);
124 result1 += TNorm(data[n + 1] * data[n + 1]);
125 result2 += TNorm(data[n + 2] * data[n + 2]);
126 result3 += TNorm(data[n + 3] * data[n + 3]);
129 TNorm result = result0 + result1 + result2 + result3;
133 while (n < ptrdiff_t(size))
135 result += TNorm(data[n] * data[n]);
143 template <
typename T,
typename TNorm>
144 TNorm
FrameNorm::squaredNormL2(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements)
146 ocean_assert(frame !=
nullptr);
147 ocean_assert(width != 0u && height != 0u);
149 if (framePaddingElements == 0u)
151 return squaredNormL2<T, TNorm>(frame, width * height);
158 TNorm result0 = TNorm(0);
159 TNorm result1 = TNorm(0);
160 TNorm result2 = TNorm(0);
161 TNorm result3 = TNorm(0);
165 for (
unsigned int y = 0u; y < height; ++y)
167 for (x = 0; x < ptrdiff_t(width) - 3; x += 4)
169 result0 += TNorm(frame[x + 0] * frame[x + 0]);
170 result1 += TNorm(frame[x + 1] * frame[x + 1]);
171 result2 += TNorm(frame[x + 2] * frame[x + 2]);
172 result3 += TNorm(frame[x + 3] * frame[x + 3]);
175 if (x + 0 < ptrdiff_t(width))
177 result0 += TNorm(frame[x + 0] * frame[x + 0]);
180 if (x + 1 < ptrdiff_t(width))
182 result1 += TNorm(frame[x + 1] * frame[x + 1]);
185 if (x + 2 < ptrdiff_t(width))
187 result2 += TNorm(frame[x + 2] * frame[x + 2]);
190 frame += width + framePaddingElements;
193 return result0 + result1 + result2 + result3;
This class implements functions allowing to determine norms of images e.g, a L2 norm.
Definition: FrameNorm.h:26
static TNorm normL2(const T *data, const size_t size)
Determines the L2 norm (square root of summed squares) of given data.
Definition: FrameNorm.h:85
static TNorm squaredNormL2(const T *data, const size_t size)
Determines the squared L2 norm (summed squares) of given data.
Definition: FrameNorm.h:103
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static T sqrt(const T value)
Returns the square root of a given value.
Definition: Numeric.h:1533
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15