144 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
145 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid image patch size, must be odd!");
147 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
149 ocean_assert(width0 >= tPatchSize + 1u);
150 ocean_assert(width1 >= tPatchSize + 1u);
152 constexpr unsigned int tPatchSize_2 = tPatchSize / 2u;
154 ocean_assert(centerX0 >=
Scalar(tPatchSize_2) && centerX0 <
Scalar(width0 - tPatchSize_2 - 1u));
155 ocean_assert_and_suppress_unused(centerY0 >=
Scalar(tPatchSize_2), tPatchSize_2);
157 ocean_assert(centerX1 >=
Scalar(tPatchSize_2) && centerX1 <
Scalar(width1 - tPatchSize_2 - 1u));
158 ocean_assert(centerY1 >=
Scalar(tPatchSize_2));
160 constexpr unsigned int tPatchPixels = tPatchSize * tPatchSize;
161 constexpr unsigned int tPatchElements = tPatchPixels * tChannels;
163 uint8_t target[tPatchElements * 2u];
165 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image0, width0, image0PaddingElements, target,
Vector2(centerX0, centerY0));
166 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image1, width1, image1PaddingElements, target + tPatchElements,
Vector2(centerX1, centerY1));
168 return ZeroMeanSumSquareDifferences::buffer8BitPerChannel<tChannels, tPatchPixels>(target, target + tPatchElements);
174 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
175 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid image patch size, must be odd!");
177 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
179 ocean_assert(width0 >= tPatchSize);
180 ocean_assert(width1 >= tPatchSize + 1u);
182 constexpr unsigned int tPatchSize_2 = tPatchSize / 2u;
184 ocean_assert(centerX0 >= tPatchSize_2 && centerX0 < width0 - tPatchSize_2);
185 ocean_assert_and_suppress_unused(centerY0 >= tPatchSize_2, tPatchSize_2);
187 ocean_assert(centerX1 >=
Scalar(tPatchSize_2) && centerX1 <
Scalar(width1 - tPatchSize_2 - 1u));
188 ocean_assert(centerY1 >=
Scalar(tPatchSize_2));
190 constexpr unsigned int tPatchPixels = tPatchSize * tPatchSize;
191 constexpr unsigned int tPatchElements = tPatchPixels * tChannels;
193 uint8_t target[tPatchElements * 2u];
195 constexpr unsigned int targetPaddingElements = 0u;
198 AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image1, width1, image1PaddingElements, target + tPatchElements,
Vector2(centerX1, centerY1));
200 return ZeroMeanSumSquareDifferences::buffer8BitPerChannel<tChannels, tPatchPixels>(target, target + tPatchElements);
204inline IndexPair32 AdvancedZeroMeanSumSquareDifferencesBase::determine8BitPerChannelPartialTemplate(
const uint8_t* frame0,
const uint8_t* frame1,
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 sizeX,
const unsigned int sizeY,
const int left0,
const int top0,
const int left1,
const int top1)
206 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
208 ocean_assert(frame0 && frame1);
209 ocean_assert(mask0 && mask1);
211 ocean_assert(sizeX >= 1u && sizeY >= 1u);
212 ocean_assert(width0 >= sizeX && width1 >= sizeX);
213 ocean_assert(height0 >= sizeY && height1 >= sizeY);
215 ocean_assert(left0 >= -
int(sizeX) + 1 && left0 <
int(width0));
216 ocean_assert(top0 >= -
int(sizeY) + 1 && top0 <
int(height0));
217 ocean_assert(left1 >= -
int(sizeX) + 1 && left1 <
int(width1));
218 ocean_assert(top1 >= -
int(sizeY) + 1 && top1 <
int(height1));
220 const int patchLeftBorder = max(0, max(-left0, -left1));
221 const int patchTopBorder = max(0, max(-top0, -top1));
223 const int patchRightBorder = max(0, max(left0 +
int(sizeX) -
int(width0), left1 +
int(sizeX) -
int(width1)));
224 const int patchBottomBorder = max(0, max(top0 +
int(sizeY) -
int(height0), top1 +
int(sizeY) -
int(height1)));
226 ocean_assert(patchLeftBorder >= 0 && patchLeftBorder <
int(sizeX));
227 ocean_assert(patchTopBorder >= 0 && patchTopBorder <
int(sizeY));
228 ocean_assert(patchRightBorder >= 0 && patchRightBorder <
int(sizeX));
229 ocean_assert(patchBottomBorder >= 0 && patchBottomBorder <
int(sizeY));
231 const int pLeft0 = left0 + patchLeftBorder;
232 const int pLeft1 = left1 + patchLeftBorder;
234 const int pTop0 = top0 + patchTopBorder;
235 const int pTop1 = top1 + patchTopBorder;
237 const unsigned int pSizeX = sizeX - patchLeftBorder - patchRightBorder;
238 const unsigned int pSizeY = sizeY - patchTopBorder - patchBottomBorder;
240 if (pSizeX > sizeX || pSizeY > sizeY)
245 unsigned int means0[tChannels] = {0u};
246 unsigned int means1[tChannels] = {0u};
248 const unsigned int pixels = sum8BitPerChannelPartialTemplate<tChannels>(frame0, frame1, mask0, mask1, width0, height0, width1, height1, sizeX, sizeY, left0, top0, left1, top1, means0, means1);
255 int means1_0[tChannels];
257 for (
unsigned int n = 0u; n < tChannels; ++n)
259 means1_0[n] = int((means1[n] + (pixels / 2u)) / pixels) - int((means0[n] + (pixels / 2u)) / pixels);
262 unsigned int ssd = 0u;
264 frame0 += (pTop0 * int(width0) + pLeft0) *
int(tChannels);
265 frame1 += (pTop1 * int(width1) + pLeft1) *
int(tChannels);
267 mask0 += (pTop0 * int(width0) + pLeft0);
268 mask1 += (pTop1 * int(width1) + pLeft1);
270 const uint8_t*
const mask0End = mask0 + pSizeY * width0;
272 while (mask0 != mask0End)
274 ocean_assert(mask0 < mask0End);
276 const uint8_t*
const mask0RowEnd = mask0 + pSizeX;
278 while (mask0 != mask0RowEnd)
280 ocean_assert(mask0 < mask0End);
281 ocean_assert(mask0 < mask0RowEnd);
283 const unsigned int factor = (*mask0 * *mask1) != 0u;
285 for (
unsigned int n = 0u; n < tChannels; ++n)
287 ssd +=
sqr(
int(frame0[n]) -
int(frame1[n]) + means1_0[n]) * factor;
297 frame0 += (width0 - pSizeX) * tChannels;
298 frame1 += (width1 - pSizeX) * tChannels;
300 mask0 += (width0 - pSizeX);
301 mask1 += (width1 - pSizeX);
304 return std::make_pair(ssd, pixels);
310 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
312 ocean_assert(frame && mask);
313 ocean_assert(width >= 1u && height >= 1u);
314 ocean_assert(sizeX >= 1u && sizeY >= 1u);
316 ocean_assert(width >= sizeX && height >= sizeY);
317 ocean_assert(left >= -
int(sizeX) + 1 && left <
int(width));
318 ocean_assert(top >= -
int(sizeY) + 1 && top <
int(height));
320 const int patchLeftBorder = max(0, -left);
321 const int patchTopBorder = max(0, -top);
323 const int patchRightBorder = max(0, left +
int(sizeX) -
int(width));
324 const int patchBottomBorder = max(0, top +
int(sizeY) -
int(height));
326 ocean_assert(patchLeftBorder >= 0 && patchLeftBorder <
int(sizeX));
327 ocean_assert(patchTopBorder >= 0 && patchTopBorder <
int(sizeY));
328 ocean_assert(patchRightBorder >= 0 && patchRightBorder <
int(sizeX));
329 ocean_assert(patchBottomBorder >= 0 && patchBottomBorder <
int(sizeY));
331 const int pLeft = left + patchLeftBorder;
332 const int pTop = top + patchTopBorder;
334 const unsigned int pSizeX = sizeX - patchLeftBorder - patchRightBorder;
335 const unsigned int pSizeY = sizeY - patchTopBorder - patchBottomBorder;
337 if (pSizeX > sizeX || pSizeY > sizeY)
342 unsigned int pixels = 0u;
344 for (
unsigned int n = 0u; n < tChannels; ++n)
349 frame += (pTop * int(width) + pLeft) *
int(tChannels);
350 mask += (pTop * int(width) + pLeft);
352 const uint8_t*
const maskEnd = mask + pSizeY * width;
354 while (mask != maskEnd)
356 ocean_assert(mask < maskEnd);
358 const uint8_t*
const maskRowEnd = mask + pSizeX;
360 while (mask != maskRowEnd)
362 ocean_assert(mask < maskEnd);
363 ocean_assert(mask < maskRowEnd);
365 const unsigned int factor = *mask != 0u;
367 for (
unsigned int n = 0u; n < tChannels; ++n)
369 sums[n] += frame[n] * factor;
378 frame += int(width - pSizeX) * int(tChannels);
379 mask += int(width - pSizeX);
386inline unsigned int AdvancedZeroMeanSumSquareDifferencesBase::sum8BitPerChannelPartialTemplate(
const uint8_t* frame0,
const uint8_t* frame1,
const uint8_t* mask0,
const uint8_t* mask1,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
unsigned int sizeX,
unsigned int sizeY,
const int left0,
const int top0,
const int left1,
const int top1,
unsigned int sums0[tChannels],
unsigned int sums1[tChannels])
388 static_assert(tChannels != 0u,
"Invalid number of frame channels!");
390 ocean_assert(frame0 && frame1);
391 ocean_assert(mask0 && mask1);
393 ocean_assert(sizeX >= 1u && sizeY >= 1u);
394 ocean_assert(width0 >= sizeX && width1 >= sizeX);
395 ocean_assert(height0 >= sizeY && height1 >= sizeY);
397 ocean_assert(left0 >= -
int(sizeX) + 1 && left0 <
int(width0));
398 ocean_assert(top0 >= -
int(sizeY) + 1 && top0 <
int(height0));
399 ocean_assert(left1 >= -
int(sizeX) + 1 && left1 <
int(width1));
400 ocean_assert(top1 >= -
int(sizeY) + 1 && top1 <
int(height1));
402 const int patchLeftBorder = max(0, max(-left0, -left1));
403 const int patchTopBorder = max(0, max(-top0, -top1));
405 const int patchRightBorder = max(0, max(left0 +
int(sizeX) -
int(width0), left1 +
int(sizeX) -
int(width1)));
406 const int patchBottomBorder = max(0, max(top0 +
int(sizeY) -
int(height0), top1 +
int(sizeY) -
int(height1)));
408 ocean_assert(patchLeftBorder >= 0 && patchLeftBorder <
int(sizeX));
409 ocean_assert(patchTopBorder >= 0 && patchTopBorder <
int(sizeY));
410 ocean_assert(patchRightBorder >= 0 && patchRightBorder <
int(sizeX));
411 ocean_assert(patchBottomBorder >= 0 && patchBottomBorder <
int(sizeY));
413 const int pLeft0 = left0 + patchLeftBorder;
414 const int pLeft1 = left1 + patchLeftBorder;
416 const int pTop0 = top0 + patchTopBorder;
417 const int pTop1 = top1 + patchTopBorder;
419 const unsigned int pSizeX = sizeX - patchLeftBorder - patchRightBorder;
420 const unsigned int pSizeY = sizeY - patchTopBorder - patchBottomBorder;
422 if (pSizeX > sizeX || pSizeY > sizeY)
427 for (
unsigned int n = 0u; n < tChannels; ++n)
431 for (
unsigned int n = 0u; n < tChannels; ++n)
436 unsigned int pixels = 0u;
438 frame0 += (pTop0 * int(width0) + pLeft0) *
int(tChannels);
439 frame1 += (pTop1 * int(width1) + pLeft1) *
int(tChannels);
441 mask0 += (pTop0 * int(width0) + pLeft0);
442 mask1 += (pTop1 * int(width1) + pLeft1);
444 const uint8_t*
const mask0End = mask0 + pSizeY * width0;
446 while (mask0 != mask0End)
448 ocean_assert(mask0 < mask0End);
450 const uint8_t*
const mask0RowEnd = mask0 + pSizeX;
452 while (mask0 != mask0RowEnd)
454 ocean_assert(mask0 < mask0End);
455 ocean_assert(mask0 < mask0RowEnd);
457 const unsigned int factor = (*mask0 * *mask1) != 0u;
459 for (
unsigned int n = 0u; n < tChannels; ++n)
461 sums0[n] += frame0[n] * factor;
464 for (
unsigned int n = 0u; n < tChannels; ++n)
466 sums1[n] += frame1[n] * factor;
478 frame0 += int(width0 - pSizeX) * int(tChannels);
479 frame1 += int(width1 - pSizeX) * int(tChannels);
481 mask0 += int(width0 - pSizeX);
482 mask1 += int(width1 - pSizeX);
static IndexPair32 determine8BitPerChannelPartialTemplate(const uint8_t *frame0, const uint8_t *frame1, const uint8_t *mask0, const uint8_t *mask1, const unsigned int width0, const unsigned int height0, const unsigned int width1, const unsigned int height1, unsigned int sizeX, unsigned int sizeY, const int left0, const int top0, const int left1, const int top1)
Determines the partial zero-mean ssd of two image patches between two frames while for each frame a b...
Definition AdvancedZeroMeanSumSquareDifferencesBase.h:204
static unsigned int sum8BitPerChannelPartialTemplate(const uint8_t *frame, const uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int sizeX, const unsigned int sizeY, const int left, const int top, unsigned int sums[tChannels])
Determines the mean values of given image patch with arbitrary sizes while a binary mask specifies wh...
Definition AdvancedZeroMeanSumSquareDifferencesBase.h:308
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 AdvancedZeroMeanSumSquareDifferencesBase.h:142
static void patchFrame(const T *source, T *buffer, const unsigned int width, const unsigned int channels, const unsigned int x, const unsigned int y, const unsigned int patchSize, const unsigned int sourcePaddingElements, const unsigned int bufferPaddingElements)
Copies a small patch area of a given frame into a buffer holding only the entire patch.
Definition FrameConverter.h:3141