8 #ifndef META_OCEAN_CV_ADVANCED_ADVANCED_SUM_SQUARE_DIFFERENCES_TEMPLATE_H
9 #define META_OCEAN_CV_ADVANCED_ADVANCED_SUM_SQUARE_DIFFERENCES_TEMPLATE_H
51 template <
unsigned int tChannels,
unsigned int tPatchSize>
52 static uint32_t patch8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int width0,
const unsigned int width1,
const Scalar centerX0,
const Scalar centerY0,
const Scalar centerX1,
const Scalar centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
70 template <
unsigned int tChannels,
unsigned int tPatchSize>
71 static 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 Scalar centerX1,
const Scalar centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
85 template <
unsigned int tChannels,
unsigned int tPatchSize>
86 static inline uint32_t patchBuffer8BitPerChannelTemplate(
const uint8_t* image0,
const unsigned int width0,
const Scalar centerX0,
const Scalar centerY0,
const unsigned int image0PaddingElements,
const uint8_t* buffer1);
112 template <
unsigned int tChannels,
unsigned int tPatchSize>
113 static IndexPair32 patchWithMask8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* mask0,
const uint8_t* mask1,
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,
const unsigned int mask0PaddingElements,
const unsigned int mask1PaddingElements,
const uint8_t maskValue);
139 template <
unsigned int tChannels,
unsigned int tPatchSize>
140 static IndexPair32 patchWithMask8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* mask0,
const uint8_t* mask1,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const Scalar centerX0,
const Scalar centerY0,
const Scalar centerX1,
const Scalar centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements,
const unsigned int mask0PaddingElements,
const unsigned int mask1PaddingElements,
const uint8_t maskValue);
158 static uint32_t
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 Scalar centerX0,
const Scalar centerY0,
const Scalar centerX1,
const Scalar centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
176 static uint32_t
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 Scalar centerX1,
const Scalar centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
190 static uint32_t
patchBuffer8BitPerChannel(
const uint8_t*
const image0,
const unsigned int channels,
const unsigned int patchSize,
const unsigned int width0,
const Scalar centerX0,
const Scalar centerY0,
const unsigned int image0PaddingElements,
const uint8_t* buffer1);
216 static IndexPair32 patchWithMask8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* mask0,
const uint8_t* mask1,
const unsigned int channels,
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,
const unsigned int mask0PaddingElements,
const unsigned int mask1PaddingElements,
const uint8_t maskValue);
243 static IndexPair32 patchWithRejectingMask8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* mask0,
const uint8_t* mask1,
const unsigned int channels,
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,
const unsigned int mask0PaddingElements,
const unsigned int mask1PaddingElements,
const uint8_t maskValue);
246 template <
unsigned int tChannels,
unsigned int tPatchSize>
249 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
250 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid image patch size, must be odd!");
252 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
254 ocean_assert(width0 >= tPatchSize + 1u);
255 ocean_assert(width1 >= tPatchSize + 1u);
257 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
259 ocean_assert(centerX0 >=
Scalar(tPatchSize_2) && centerX0 <
Scalar(width0 - tPatchSize_2 - 1u));
260 ocean_assert_and_suppress_unused(centerY0 >=
Scalar(tPatchSize_2), tPatchSize_2);
262 ocean_assert(centerX1 >=
Scalar(tPatchSize_2) && centerX1 <
Scalar(width1 - tPatchSize_2 - 1u));
263 ocean_assert(centerY1 >=
Scalar(tPatchSize_2));
265 constexpr
unsigned int tPatchElements = tPatchSize * tPatchSize * tChannels;
267 uint8_t target[tPatchElements * 2u];
269 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image0, width0, image0PaddingElements, target,
Vector2(centerX0, centerY0));
270 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image1, width1, image1PaddingElements, target + tPatchElements,
Vector2(centerX1, centerY1));
272 return SumSquareDifferences::buffer8BitPerChannelTemplate<tPatchElements>(target, target + tPatchElements);
275 template <
unsigned int tChannels,
unsigned int tPatchSize>
278 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
279 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid image patch size, must be odd!");
281 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
283 ocean_assert(width0 >= tPatchSize);
284 ocean_assert(width1 >= tPatchSize + 1u);
286 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
288 ocean_assert(centerX0 >= tPatchSize_2 && centerX0 < width0 - tPatchSize_2);
289 ocean_assert_and_suppress_unused(centerY0 >= tPatchSize_2, tPatchSize_2);
291 ocean_assert(centerX1 >=
Scalar(tPatchSize_2) && centerX1 <
Scalar(width1 - tPatchSize_2 - 1u));
292 ocean_assert(centerY1 >=
Scalar(tPatchSize_2));
294 constexpr
unsigned int tPatchPixels = tPatchSize * tPatchSize;
296 constexpr
unsigned int tPatchElements = tPatchPixels * tChannels;
298 uint8_t target[tPatchElements * 2u];
300 constexpr
unsigned int targetPaddingElements = 0u;
302 CV::FrameConverter::patchFrame<uint8_t>(image0, target, width0, tChannels, centerX0, centerY0, tPatchSize, image0PaddingElements, targetPaddingElements);
303 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image1, width1, image1PaddingElements, target + tPatchElements,
Vector2(centerX1, centerY1));
305 return SumSquareDifferences::buffer8BitPerChannel<tChannels, tPatchPixels>(target, target + tPatchElements);
308 template <
unsigned int tChannels,
unsigned int tPatchSize>
311 static_assert(tChannels != 0u,
"Invalid number of image channels!");
312 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid patch size!");
314 ocean_assert(image0 !=
nullptr && buffer1 !=
nullptr);
316 ocean_assert(width0 >= tPatchSize + 1u);
318 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
320 ocean_assert_and_suppress_unused(centerX0 >=
Scalar(tPatchSize_2) && centerX0 <
Scalar(width0 - tPatchSize_2 - 1u), tPatchSize_2);
322 constexpr
unsigned int tPatchPixels = tPatchSize * tPatchSize;
324 uint8_t target[tPatchPixels * tChannels];
325 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image0, width0, image0PaddingElements, target,
Vector2(centerX0, centerY0));
326 return SumSquareDifferences::buffer8BitPerChannel<tChannels, tPatchPixels>(target, buffer1);
329 template <
unsigned int tChannels,
unsigned int tPatchSize>
330 IndexPair32 AdvancedSumSquareDifferencesBase::patchWithMask8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* mask0,
const uint8_t* mask1,
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,
const unsigned int mask0PaddingElements,
const unsigned int mask1PaddingElements,
const uint8_t maskValue)
332 static_assert(tChannels >= 1u,
"Invalid channel number!");
333 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid patch size!");
335 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
336 ocean_assert(mask0 !=
nullptr && mask1 !=
nullptr);
338 const unsigned int patchSize_2 = tPatchSize / 2u;
340 ocean_assert(width0 >= patchSize_2 + 1u && height0 >= patchSize_2 + 1u);
341 ocean_assert(width1 >= patchSize_2 + 1u && height1 >= patchSize_2 + 1u);
343 ocean_assert(centerX0 < width0 && centerY0 < height0);
344 ocean_assert(centerX1 < width1 && centerY1 < height1);
346 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
347 const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
349 const unsigned int mask0StrideElements = width0 + mask0PaddingElements;
350 const unsigned int mask1StrideElements = width1 + mask1PaddingElements;
352 const unsigned int offsetLeft = std::min(std::min(centerX0, patchSize_2), std::min(centerX1, patchSize_2));
353 const unsigned int offsetTop = std::min(std::min(centerY0, patchSize_2), std::min(centerY1, patchSize_2));
355 const unsigned int offsetRight = std::min(std::min(width0 - centerX0 - 1u, patchSize_2), std::min(width1 - centerX1 - 1u, patchSize_2));
356 const unsigned int offsetBottom = std::min(std::min(height0 - centerY0 - 1u, patchSize_2), std::min(height1 - centerY1 - 1u, patchSize_2));
358 ocean_assert(offsetLeft <= patchSize_2 && offsetRight <= patchSize_2);
359 ocean_assert(offsetTop <= patchSize_2 && offsetTop <= patchSize_2);
361 ocean_assert(offsetLeft <= centerX0 && offsetTop <= centerY0);
362 ocean_assert(offsetTop <= centerY1 && offsetTop <= centerY1);
364 ocean_assert(centerX0 + offsetRight < width0 && centerY0 + offsetBottom < height0);
365 ocean_assert(centerX1 + offsetRight < width1 && centerY1 + offsetBottom < height1);
367 const unsigned int patchWidth = offsetLeft + offsetRight + 1u;
368 const unsigned int patchHeight = offsetTop + offsetBottom + 1u;
370 ocean_assert(patchWidth <= tPatchSize && patchHeight <= tPatchSize);
372 image0 += (centerY0 - offsetTop) * image0StrideElements + (centerX0 - offsetLeft) * tChannels;
373 image1 += (centerY1 - offsetTop) * image1StrideElements + (centerX1 - offsetLeft) * tChannels;
375 mask0 += (centerY0 - offsetTop) * mask0StrideElements + (centerX0 - offsetLeft);
376 mask1 += (centerY1 - offsetTop) * mask1StrideElements + (centerX1 - offsetLeft);
378 uint32_t validPixels = 0u;
381 for (
unsigned int y = 0u; y < patchHeight; ++y)
383 for (
unsigned int x = 0u; x < patchWidth; ++x)
385 if (mask0[x] != maskValue && mask1[x] != maskValue)
387 for (
unsigned int n = 0u; n < tChannels; ++n)
389 ssd +=
sqr(image0[tChannels * x + n] - image1[tChannels * x + n]);
396 image0 += image0StrideElements;
397 image1 += image1StrideElements;
399 mask0 += mask0StrideElements;
400 mask1 += mask1StrideElements;
406 template <
unsigned int tChannels,
unsigned int tPatchSize>
407 inline IndexPair32 AdvancedSumSquareDifferencesBase::patchWithMask8BitPerChannelTemplate(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* mask0,
const uint8_t* mask1,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const Scalar centerX0,
const Scalar centerY0,
const Scalar centerX1,
const Scalar centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements,
const unsigned int mask0PaddingElements,
const unsigned int mask1PaddingElements,
const uint8_t maskValue)
409 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
411 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
412 ocean_assert(mask0 !=
nullptr && mask1 !=
nullptr);
414 uint8_t patchBuffers[tPatchSize * tPatchSize * tChannels * 2u];
415 uint8_t maskBuffers[tPatchSize * tPatchSize * 2u];
417 uint8_t* patchBuffer0 = patchBuffers;
418 uint8_t* patchBuffer1 = patchBuffers + tPatchSize * tPatchSize * tChannels;
420 uint8_t* maskBuffer0 = maskBuffers;
421 uint8_t* maskBuffer1 = maskBuffers + tPatchSize * tPatchSize;
423 constexpr
unsigned int patchBuffer0PaddingElements = 0u;
424 constexpr
unsigned int patchBuffer1PaddingElements = 0u;
426 constexpr
unsigned int maskBuffer0PaddingElements = 0u;
427 constexpr
unsigned int maskBuffer1PaddingElements = 0u;
429 const uint8_t validMaskValue = 0xFFu - maskValue;
431 AdvancedFrameInterpolatorBilinear::interpolatePatchWithMask8BitPerChannel<tChannels, PC_CENTER>(image0, mask0, width0, height0, image0PaddingElements, mask0PaddingElements,
Vector2(centerX0, centerY0), patchBuffer0, maskBuffer0, tPatchSize, tPatchSize, patchBuffer0PaddingElements, maskBuffer0PaddingElements, validMaskValue);
432 AdvancedFrameInterpolatorBilinear::interpolatePatchWithMask8BitPerChannel<tChannels, PC_CENTER>(image1, mask1, width1, height1, image1PaddingElements, mask1PaddingElements,
Vector2(centerX1, centerY1), patchBuffer1, maskBuffer1, tPatchSize, tPatchSize, patchBuffer1PaddingElements, maskBuffer1PaddingElements, validMaskValue);
435 uint32_t validPixels = 0u;
437 for (
unsigned int y = 0u; y < tPatchSize; ++y)
439 for (
unsigned int x = 0u; x < tPatchSize; ++x)
441 if (*maskBuffer0 == validMaskValue && *maskBuffer1 == validMaskValue)
443 for (
unsigned int n = 0u; n < tChannels; ++n)
445 ssd +=
sqrDistance(patchBuffer0[n], patchBuffer1[n]);
451 patchBuffer0 += tChannels;
452 patchBuffer1 += tChannels;
This class implements functions calculating the sum of square differences and omit center pixel.
Definition: AdvancedSumSquareDifferencesBase.h:32
static uint32_t 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 Scalar centerX1, const Scalar centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of square differences between two square patches, one with sub-pixel accuracy,...
static IndexPair32 patchWithMask8BitPerChannel(const uint8_t *image0, const uint8_t *image1, const uint8_t *mask0, const uint8_t *mask1, const unsigned int channels, 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, const unsigned int mask0PaddingElements, const unsigned int mask1PaddingElements, const uint8_t maskValue)
Returns the sum of square differences for an image patch determined for two pixel accurate positions ...
static uint32_t patch8BitPerChannelTemplate(const uint8_t *image0, const uint8_t *image1, const unsigned int width0, const unsigned int width1, const Scalar centerX0, const Scalar centerY0, const Scalar centerX1, const Scalar centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of square differences for an image patch determined between two individual images.
Definition: AdvancedSumSquareDifferencesBase.h:247
static IndexPair32 patchWithMask8BitPerChannelTemplate(const uint8_t *image0, const uint8_t *image1, const uint8_t *mask0, const uint8_t *mask1, 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, const unsigned int mask0PaddingElements, const unsigned int mask1PaddingElements, const uint8_t maskValue)
Returns the sum of square differences for an image patch determined for two pixel accurate positions ...
Definition: AdvancedSumSquareDifferencesBase.h:330
static IndexPair32 patchWithRejectingMask8BitPerChannel(const uint8_t *image0, const uint8_t *image1, const uint8_t *mask0, const uint8_t *mask1, const unsigned int channels, 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, const unsigned int mask0PaddingElements, const unsigned int mask1PaddingElements, const uint8_t maskValue)
Returns the sum of square differences for an image patch determined for two pixel accurate positions ...
static uint32_t patchBuffer8BitPerChannelTemplate(const uint8_t *image0, const unsigned int width0, const Scalar centerX0, const Scalar centerY0, const unsigned int image0PaddingElements, const uint8_t *buffer1)
Determines the sum of square differences between an image patch with sub-pixel accuracy and a memory ...
Definition: AdvancedSumSquareDifferencesBase.h:309
static uint32_t patchBuffer8BitPerChannel(const uint8_t *const image0, const unsigned int channels, const unsigned int patchSize, const unsigned int width0, const Scalar centerX0, const Scalar centerY0, const unsigned int image0PaddingElements, const uint8_t *buffer1)
Returns the sum of square differences between one sub-pixel image patch and a memory buffer.
static uint32_t 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 Scalar centerX0, const Scalar centerY0, const Scalar centerX1, const Scalar centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of square differences between two square patches with sub-pixel accuracy.
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition: base/Utilities.h:1089
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
std::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition: Base.h:138
float Scalar
Definition of a scalar type.
Definition: Math.h:128
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15