8 #ifndef META_OCEAN_CV_FRAME_FILTER_H
9 #define META_OCEAN_CV_FRAME_FILTER_H
45 template <
typename T,
typename TMagnitude>
46 static void magnitude(
const T* frame, TMagnitude* magnitude,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int magnitudePaddingElements,
Worker* worker =
nullptr);
66 template <
typename T, T tNormalizationDenominator,
bool tRoundedNormalization>
67 static inline T normalizeValue(
const T& value);
79 template <
typename T, T tNormalizationDenominator,
bool tRoundedNormalization>
80 static inline T normalizeValueSlow(
const T& value);
98 template <
typename T,
typename TMagnitude>
99 static void magnitudeSubset(
const T* frame, TMagnitude* magnitude,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int magnitudePaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
114 static void magnitude2Channels8BitPerChannelSubset(
const uint8_t* frame, uint16_t* magnitude,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int magnitudePaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
117 template <
typename T,
typename TMagnitude>
118 void FrameFilter::magnitude(
const T* frame, TMagnitude* magnitude,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int magnitudePaddingElements,
Worker* worker)
120 static_assert(
sizeof(T) <=
sizeof(TMagnitude),
"Invalid data type!");
122 ocean_assert(frame !=
nullptr);
124 ocean_assert(channels >= 2u);
125 ocean_assert(width >= 1u && height >= 1u);
127 if (worker !=
nullptr)
129 worker->
executeFunction(
Worker::Function::createStatic(&magnitudeSubset<T, TMagnitude>, frame,
magnitude, channels, width, height, framePaddingElements, magnitudePaddingElements, 0u, 0u), 0u, height);
133 magnitudeSubset<T, TMagnitude>(frame,
magnitude, channels, width, height, framePaddingElements, magnitudePaddingElements, 0u, height);
137 template <
typename T, T tNormalizationDenominator,
bool tRoundedNormalization>
140 static_assert(tNormalizationDenominator > T(0),
"Invalid normalization!");
142 if constexpr (tNormalizationDenominator == T(1))
147 if constexpr (std::is_floating_point<T>::value)
149 return value / tNormalizationDenominator;
153 constexpr T tNormalizationDenominator_2 = tNormalizationDenominator / T(2);
156 ocean_assert((std::is_integral<T>::value));
158 if constexpr (tRoundedNormalization)
160 if constexpr (std::is_same<T, int32_t>::value)
166 if constexpr (std::is_same<T, uint32_t>::value)
171 if constexpr (std::is_same<T, int64_t>::value)
177 if constexpr (std::is_same<T, uint64_t>::value)
184 if constexpr (tRoundedNormalization && std::is_signed<T>::value)
188 return (value + tNormalizationDenominator_2) / tNormalizationDenominator;
192 return (value - tNormalizationDenominator_2) / tNormalizationDenominator;
197 if constexpr (tRoundedNormalization)
199 return (value + tNormalizationDenominator_2) / tNormalizationDenominator;
203 return value / tNormalizationDenominator;
209 template <
typename T, T tNormalizationDenominator,
bool tRoundedNormalization>
212 if constexpr (std::is_integral<T>::value && tNormalizationDenominator != T(1) && tRoundedNormalization &&
sizeof(T) >= 4)
214 constexpr T tNormalizationDenominator_2 = (tNormalizationDenominator + 1) / T(2);
216 if constexpr (std::is_signed<T>::value)
220 const T remainder = value % tNormalizationDenominator;
222 if (remainder <= -tNormalizationDenominator_2)
224 return value / tNormalizationDenominator - T(1);
228 return value / tNormalizationDenominator;
234 const T remainder = value % tNormalizationDenominator;
236 if (remainder >= tNormalizationDenominator_2)
238 return value / tNormalizationDenominator + T(1);
242 return value / tNormalizationDenominator;
247 return normalizeValue<T, tNormalizationDenominator, tRoundedNormalization>(value);
251 template <
typename T,
typename TMagnitude>
252 void FrameFilter::magnitudeSubset(
const T* frame, TMagnitude* magnitude,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int magnitudePaddingElements,
const unsigned int firstRow,
const unsigned int numberRows)
254 static_assert(
sizeof(T) <=
sizeof(TMagnitude),
"Invalid data type!");
256 ocean_assert(frame !=
nullptr);
258 ocean_assert(channels >= 2u);
259 ocean_assert(width >= 1u && height >= 1u);
261 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
263 if constexpr (std::is_same<T, uint8_t>::value && std::is_same<TMagnitude, uint16_t>::value)
275 const unsigned int frameStrideElements = width * channels + framePaddingElements;
276 const unsigned int magnitudeStrideElements = width + magnitudePaddingElements;
278 frame += firstRow * frameStrideElements;
279 magnitude += firstRow * magnitudeStrideElements;
281 for (
unsigned int y = 0u; y < numberRows; ++y)
283 for (
unsigned int x = 0u; x < width; ++x)
285 TSqrMagnitude sqrMagnitude = TSqrMagnitude(0);
287 for (
unsigned int n = 0u; n < channels; ++n)
289 sqrMagnitude += TSqrMagnitude(frame[n]) * TSqrMagnitude(frame[n]);
294 if constexpr (std::is_floating_point<TMagnitude>::value)
310 frame += framePaddingElements;
This class implements the base class for all filter.
Definition: FrameFilter.h:29
static T normalizeValueSlow(const T &value)
Normalizes a given value with a template-based normalization factor.
Definition: FrameFilter.h:210
static T normalizeValue(const T &value)
Normalizes a given value with a template-based normalization factor.
Definition: FrameFilter.h:138
static void magnitude(const T *frame, TMagnitude *magnitude, const unsigned int channels, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int magnitudePaddingElements, Worker *worker=nullptr)
Determines the per-pixel magnitude of a frame.
Definition: FrameFilter.h:118
static void magnitudeSubset(const T *frame, TMagnitude *magnitude, const unsigned int channels, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int magnitudePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Determines the per-pixel magnitude for a subset of a frame.
Definition: FrameFilter.h:252
static void magnitude2Channels8BitPerChannelSubset(const uint8_t *frame, uint16_t *magnitude, const unsigned int channels, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int magnitudePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Determines the per-pixel magnitude for a subset of a frame.
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
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
T Type
Definition of the data type for the square value.
Definition: DataType.h:132
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
float Type
The 32 bit floating point data type for any data type T but 'double'.
Definition: DataType.h:373