8 #ifndef META_OCEAN_CV_SUM_ABSOLUTE_DIFFERENCES_BASE_H
9 #define META_OCEAN_CV_SUM_ABSOLUTE_DIFFERENCES_BASE_H
44 template <
unsigned int tChannels,
unsigned int tPatchSize>
45 static OCEAN_FORCE_INLINE uint32_t patch8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int width0,
const unsigned int width1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
57 template <
unsigned int tChannels,
unsigned int tPatchSize>
58 static uint32_t patch8BitPerChannelTemplate(
const uint8_t* patch0,
const uint8_t* patch1,
const unsigned int patch0StrideElements,
const unsigned int patch1StrideElements);
72 template <
unsigned int tChannels,
unsigned int tPatchSize>
73 static OCEAN_FORCE_INLINE uint32_t patchBuffer8BitPerChannelTemplate(
const uint8_t* image0,
const unsigned int width0,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int image0PaddingElements,
const uint8_t* buffer1);
84 template <
unsigned int tChannels,
unsigned int tPatchSize>
85 static uint32_t patchBuffer8BitPerChannelTemplate(
const uint8_t* patch0,
const uint8_t* buffer1,
const unsigned int patch0StrideElements);
94 template <
unsigned int tBufferSize>
95 static inline uint32_t buffer8BitPerChannelTemplate(
const uint8_t*
const buffer0,
const uint8_t*
const buffer1);
115 template <
unsigned int tChannels>
116 static uint32_t patchMirroredBorder8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int patchSize,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
136 static OCEAN_FORCE_INLINE uint32_t patch8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int channels,
const unsigned int patchSize,
const unsigned int width0,
const unsigned int width1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
148 static uint32_t
patch8BitPerChannel(
const uint8_t* patch0,
const uint8_t* patch1,
const unsigned int channels,
const unsigned int patchSize,
const unsigned int patch0StrideElements,
const unsigned int patch1StrideElements);
162 static OCEAN_FORCE_INLINE uint32_t patchBuffer8BitPerChannel(
const uint8_t* image0,
unsigned int channels,
unsigned int patchSize,
const unsigned int width0,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int image0PaddingElements,
const uint8_t* buffer1);
173 static inline uint32_t patchBuffer8BitPerChannel(
const uint8_t* patch0,
const uint8_t* buffer1,
unsigned int channels,
unsigned int patchSize,
const unsigned int patch0StrideElements);
182 static uint32_t
buffer8BitPerChannel(
const uint8_t*
const buffer0,
const uint8_t*
const buffer1,
const unsigned int bufferSize);
185 template <
unsigned int tChannels,
unsigned int tPatchSize>
186 OCEAN_FORCE_INLINE uint32_t
SumAbsoluteDifferencesBase::patch8BitPerChannelTemplate(
const uint8_t*
const image0,
const uint8_t*
const image1,
const unsigned int width0,
const unsigned int width1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements)
188 static_assert(tChannels >= 1u,
"Invalid number of frame channels!");
189 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
191 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
193 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
195 ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2 && centerX0 < width0 - tPatchSize_2);
196 ocean_assert(centerX1 >= tPatchSize_2 && centerY1 >= tPatchSize_2 && centerX1 < width1 - tPatchSize_2);
198 ocean_assert(width0 >= tPatchSize);
199 ocean_assert(width1 >= tPatchSize);
201 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
202 const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
204 return patch8BitPerChannelTemplate<tChannels, tPatchSize>(image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels, image1 + (centerY1 - tPatchSize_2) * image1StrideElements + (centerX1 - tPatchSize_2) * tChannels, image0StrideElements, image1StrideElements);
207 template <
unsigned int tChannels,
unsigned int tPatchSize>
210 static_assert(tPatchSize >= 1u,
"Invalid image patch size, need an odd value!");
211 static_assert(tChannels > 0u,
"Invalid number of frame channels!");
213 ocean_assert(patch0 !=
nullptr && patch1 !=
nullptr);
215 ocean_assert(patch0StrideElements >= tPatchSize * tChannels);
216 ocean_assert(patch1StrideElements >= tPatchSize * tChannels);
218 uint32_t result = 0u;
221 for (
unsigned int y = 0u; y < tPatchSize; ++y)
223 for (
unsigned int n = 0u; n < tPatchSize * tChannels; ++n)
225 value = int16_t(patch0[n]) - int16_t(patch1[n]);
226 result += std::abs(value);
229 patch0 += patch0StrideElements;
230 patch1 += patch1StrideElements;
236 template <
unsigned int tChannels,
unsigned int tPatchSize>
239 static_assert(tChannels >= 1u,
"Invalid number of frame channels!");
240 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
242 ocean_assert(image0 !=
nullptr && buffer1 !=
nullptr);
244 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
246 ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2 && centerX0 < width0 - tPatchSize_2);
248 ocean_assert(width0 >= tPatchSize);
250 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
252 return patchBuffer8BitPerChannelTemplate<tChannels, tPatchSize>(image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels, buffer1, image0StrideElements);
255 template <
unsigned int tChannels,
unsigned int tPatchSize>
258 return patch8BitPerChannelTemplate<tChannels, tPatchSize>(patch0, buffer1, patch0StrideElements, tChannels * tPatchSize);
261 template <
unsigned int tBufferSize>
264 static_assert(tBufferSize != 0u,
"Invalid number of frame channels!");
266 ocean_assert(buffer0 !=
nullptr && buffer1 !=
nullptr);
271 for (
unsigned int n = 0u; n < tBufferSize; ++n)
273 difference = int16_t(buffer0[n]) - int16_t(buffer1[n]);
274 ssd += uint32_t(std::abs(difference));
280 template <
unsigned int tChannels>
281 uint32_t
SumAbsoluteDifferencesBase::patchMirroredBorder8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int patchSize,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements)
283 static_assert(tChannels != 0u,
"Invalid number of data channels!");
285 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
286 ocean_assert(patchSize % 2u == 1u);
288 const unsigned int patchSize_2 = patchSize / 2u;
290 ocean_assert(width0 >= patchSize_2);
291 ocean_assert(width1 >= patchSize_2);
293 ocean_assert(centerX0 < width0 && centerY0 < height0);
294 ocean_assert(centerX1 < width1 && centerY1 < height1);
296 const int left0 = int(centerX0 - patchSize_2);
297 const int top0 = int(centerY0 - patchSize_2);
299 const int left1 = int(centerX1 - patchSize_2);
300 const int top1 = int(centerY1 - patchSize_2);
302 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
303 const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
305 const uint8_t* i0 = image0 + top0 * int(image0StrideElements) + left0 * int(tChannels);
306 const uint8_t* i1 = image1 + top1 * int(image1StrideElements) + left1 * int(tChannels);
310 unsigned int y0 = centerY0 - patchSize_2;
311 unsigned int y1 = centerY1 - patchSize_2;
313 const uint8_t*
const i0End = i0 + patchSize * image0StrideElements;
317 ocean_assert(i0 < i0End);
322 unsigned int x0 = centerX0 - patchSize_2;
323 unsigned int x1 = centerX1 - patchSize_2;
325 const uint8_t*
const c0RowEnd = c0 + patchSize * tChannels;
327 while (c0 != c0RowEnd)
329 ocean_assert(c0 < c0RowEnd);
331 if (x0 < width0 && x1 < width1)
335 for (
unsigned int n = 0u; n < tChannels; ++n)
337 sad += abs(*c0++ - *c1++);
340 else if (x0 < width0)
344 ocean_assert(x1 >= width1);
348 for (
unsigned int n = 0u; n < tChannels; ++n)
350 sad += abs(*c0++ - *m1++);
355 else if (x1 < width1)
359 ocean_assert(x0 >= width0);
363 for (
unsigned int n = 0u; n < tChannels; ++n)
365 sad += abs(*m0++ - *c1++);
374 ocean_assert(x0 >= width0 && x1 >= width1);
379 for (
unsigned int n = 0u; n < tChannels; ++n)
381 sad += abs(*m0++ - *m1++);
392 i0 += image0StrideElements;
393 i1 += image1StrideElements;
402 OCEAN_FORCE_INLINE uint32_t
SumAbsoluteDifferencesBase::patch8BitPerChannel(
const uint8_t*
const image0,
const uint8_t*
const image1,
const unsigned int channels,
const unsigned int patchSize,
const unsigned int width0,
const unsigned int width1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements)
404 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
406 ocean_assert(channels >= 1u);
407 ocean_assert(patchSize % 2u == 1u);
409 const unsigned int patchSize_2 = patchSize / 2u;
411 ocean_assert(centerX0 >= patchSize_2 && centerY0 >= patchSize_2 && centerX0 < width0 - patchSize_2);
412 ocean_assert(centerX1 >= patchSize_2 && centerY1 >= patchSize_2 && centerX1 < width1 - patchSize_2);
414 ocean_assert(width0 >= patchSize);
415 ocean_assert(width1 >= patchSize);
417 const unsigned int image0StrideElements = width0 * channels + image0PaddingElements;
418 const unsigned int image1StrideElements = width1 * channels + image1PaddingElements;
420 return patch8BitPerChannel(image0 + (centerY0 - patchSize_2) * image0StrideElements + (centerX0 - patchSize_2) * channels, image1 + (centerY1 - patchSize_2) * image1StrideElements + (centerX1 - patchSize_2) * channels, channels, patchSize, image0StrideElements, image1StrideElements);
423 OCEAN_FORCE_INLINE uint32_t
SumAbsoluteDifferencesBase::patchBuffer8BitPerChannel(
const uint8_t* image0,
unsigned int channels,
unsigned int patchSize,
const unsigned int width0,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int image0PaddingElements,
const uint8_t* buffer1)
425 ocean_assert(image0 !=
nullptr && buffer1 !=
nullptr);
427 ocean_assert(channels >= 1u);
428 ocean_assert(patchSize % 2u == 1u);
430 const unsigned int patchSize_2 = patchSize / 2u;
432 ocean_assert(centerX0 >= patchSize_2 && centerY0 >= patchSize_2 && centerX0 < width0 - patchSize_2);
434 ocean_assert(width0 >= patchSize);
436 const unsigned int image0StrideElements = width0 * channels + image0PaddingElements;
438 return patchBuffer8BitPerChannel(image0 + (centerY0 - patchSize_2) * image0StrideElements + (centerX0 - patchSize_2) * channels, buffer1, channels, patchSize, image0StrideElements);
443 return patch8BitPerChannel(patch0, buffer1, channels, patchSize, patch0StrideElements, channels * patchSize);
static int mirrorOffset(const unsigned int index, const unsigned int elements)
Deprecated.
Definition: CVUtilities.h:446
This class implements several sum of absolute differences functions.
Definition: SumAbsoluteDifferencesBase.h:25
static OCEAN_FORCE_INLINE uint32_t patch8BitPerChannelTemplate(const uint8_t *image0, const uint8_t *image1, const unsigned int width0, const unsigned int width1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of absolute differences between two square patches.
Definition: SumAbsoluteDifferencesBase.h:186
static OCEAN_FORCE_INLINE uint32_t patch8BitPerChannel(const uint8_t *image0, const uint8_t *image1, const unsigned int channels, const unsigned int patchSize, const unsigned int width0, const unsigned int width1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of absolute differences between two square patches.
Definition: SumAbsoluteDifferencesBase.h:402
static OCEAN_FORCE_INLINE uint32_t patchBuffer8BitPerChannelTemplate(const uint8_t *image0, const unsigned int width0, const unsigned int centerX0, const unsigned int centerY0, const unsigned int image0PaddingElements, const uint8_t *buffer1)
Returns the sum of absolute differences between a square image patch and a buffer.
Definition: SumAbsoluteDifferencesBase.h:237
static uint32_t patchMirroredBorder8BitPerChannelTemplate(const uint8_t *image0, const uint8_t *image1, const unsigned int patchSize, const unsigned int width0, const unsigned int height0, const unsigned int width1, const unsigned int height1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of absolute differences between two patches within an image, patch pixels outside the...
Definition: SumAbsoluteDifferencesBase.h:281
static uint32_t patch8BitPerChannel(const uint8_t *patch0, const uint8_t *patch1, const unsigned int channels, const unsigned int patchSize, const unsigned int patch0StrideElements, const unsigned int patch1StrideElements)
Returns the sum of absolute differences between two square patches.
static OCEAN_FORCE_INLINE uint32_t patchBuffer8BitPerChannel(const uint8_t *image0, unsigned int channels, unsigned int patchSize, const unsigned int width0, const unsigned int centerX0, const unsigned int centerY0, const unsigned int image0PaddingElements, const uint8_t *buffer1)
Returns the sum of absolute differences between a square image patch and a buffer.
Definition: SumAbsoluteDifferencesBase.h:423
static uint32_t buffer8BitPerChannelTemplate(const uint8_t *const buffer0, const uint8_t *const buffer1)
Returns the sum of absolute differences between two individual buffers.
Definition: SumAbsoluteDifferencesBase.h:262
static uint32_t buffer8BitPerChannel(const uint8_t *const buffer0, const uint8_t *const buffer1, const unsigned int bufferSize)
Returns the sum of absolute differences between two individual buffers.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15