Functions for estimation of correlation. More...
Functions | |
| SIMD_API void | SimdAbsDifference (const uint8_t *a, size_t aStride, const uint8_t *b, size_t bStride, uint8_t *c, size_t cStride, size_t width, size_t height) |
| Calculates per-pixel absolute difference of two gray 8-bit images. More... | |
| SIMD_API void | SimdAbsDifferenceSum (const uint8_t *a, size_t aStride, const uint8_t *b, size_t bStride, size_t width, size_t height, uint64_t *sum) |
| Calculates sum of absolute differences (SAD) of two gray 8-bit images. More... | |
| SIMD_API void | SimdAbsDifferenceSumMasked (const uint8_t *a, size_t aStride, const uint8_t *b, size_t bStride, const uint8_t *mask, size_t maskStride, uint8_t index, size_t width, size_t height, uint64_t *sum) |
| Calculates masked sum of absolute differences (SAD) of two gray 8-bit images. More... | |
| SIMD_API void | SimdAbsDifferenceSums3x3 (const uint8_t *current, size_t currentStride, const uint8_t *background, size_t backgroundStride, size_t width, size_t height, uint64_t *sums) |
| Calculates 9 sums of absolute differences for all shifts in 3x3 neighborhood. More... | |
| SIMD_API void | SimdAbsDifferenceSums3x3Masked (const uint8_t *current, size_t currentStride, const uint8_t *background, size_t backgroundStride, const uint8_t *mask, size_t maskStride, uint8_t index, size_t width, size_t height, uint64_t *sums) |
| Calculates 9 masked sums of absolute differences for all shifts in 3x3 neighborhood. More... | |
| SIMD_API void | SimdCosineDistance32f (const float *a, const float *b, size_t size, float *distance) |
| Calculates the cosine distance between two 32-bit floating-point vectors. More... | |
| SIMD_API void | SimdSquaredDifferenceSum (const uint8_t *a, size_t aStride, const uint8_t *b, size_t bStride, size_t width, size_t height, uint64_t *sum) |
| Calculates the sum of squared differences for two 8-bit gray images. More... | |
| SIMD_API void | SimdSquaredDifferenceSumMasked (const uint8_t *a, size_t aStride, const uint8_t *b, size_t bStride, const uint8_t *mask, size_t maskStride, uint8_t index, size_t width, size_t height, uint64_t *sum) |
| Calculates the masked sum of squared differences for two 8-bit gray images. More... | |
| SIMD_API void | SimdSquaredDifferenceSum32f (const float *a, const float *b, size_t size, float *sum) |
| Calculates the sum of squared differences for two 32-bit float arrays. More... | |
| SIMD_API void | SimdSquaredDifferenceKahanSum32f (const float *a, const float *b, size_t size, float *sum) |
| Calculates the sum of squared differences for two 32-bit float arrays using Kahan summation. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | AbsDifference (const View< A > &a, const View< A > &b, View< A > &c) |
| Gets absolute difference of two gray 8-bit images, pixel by pixel. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | AbsDifferenceSum (const View< A > &a, const View< A > &b, uint64_t &sum) |
| Gets sum of absolute difference of two gray 8-bit images. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | AbsDifferenceSum (const View< A > &a, const View< A > &b, const View< A > &mask, uint8_t index, uint64_t &sum) |
| Gets sum of absolute difference of two gray 8-bit images based on gray 8-bit mask. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | AbsDifferenceSums3x3 (const View< A > ¤t, const View< A > &background, uint64_t *sums) |
| Gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | AbsDifferenceSums3x3 (const View< A > ¤t, const View< A > &background, const View< A > &mask, uint8_t index, uint64_t *sums) |
| Gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3 based on gray 8-bit mask. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | SquaredDifferenceSum (const View< A > &a, const View< A > &b, uint64_t &sum) |
| Calculates sum of squared differences for two 8-bit gray images. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | SquaredDifferenceSum (const View< A > &a, const View< A > &b, const View< A > &mask, uint8_t index, uint64_t &sum) |
| Calculates sum of squared differences for two images with using mask. More... | |
Detailed Description
Functions for estimation of correlation.
Function Documentation
◆ SimdAbsDifference()
| void SimdAbsDifference | ( | const uint8_t * | a, |
| size_t | aStride, | ||
| const uint8_t * | b, | ||
| size_t | bStride, | ||
| uint8_t * | c, | ||
| size_t | cStride, | ||
| size_t | width, | ||
| size_t | height | ||
| ) |
Calculates per-pixel absolute difference of two gray 8-bit images.
The destination pixel values are computed as:
c[x, y] = abs(a[x, y] - b[x, y]).
All three images must have the same width and height.
- Note
- This function has a C++ wrapper Simd::AbsDifference(const View<A> & a, const View<A> & b, View<A> & c).
- Parameters
-
[in] a - a pointer to pixels data of first image. [in] aStride - a row size of first image. [in] b - a pointer to pixels data of second image. [in] bStride - a row size of second image. [out] c - a pointer to pixels data of destination image. [in] cStride - a row size of destination image. [in] width - an image width. [in] height - an image height.
◆ SimdAbsDifferenceSum()
| void SimdAbsDifferenceSum | ( | const uint8_t * | a, |
| size_t | aStride, | ||
| const uint8_t * | b, | ||
| size_t | bStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint64_t * | sum | ||
| ) |
Calculates sum of absolute differences (SAD) of two gray 8-bit images.
The result value is computed as:
sum = Σ abs(a[x, y] - b[x, y]).
Both images must have the same width and height.
- Note
- This function has a C++ wrapper Simd::AbsDifferenceSum(const View<A> & a, const View<A> & b, uint64_t & sum).
- Parameters
-
[in] a - a pointer to pixels data of first image. [in] aStride - a row size of first image. [in] b - a pointer to pixels data of second image. [in] bStride - a row size of second image. [in] width - an image width. [in] height - an image height. [out] sum - the result sum of absolute difference of two images.
◆ SimdAbsDifferenceSumMasked()
| void SimdAbsDifferenceSumMasked | ( | const uint8_t * | a, |
| size_t | aStride, | ||
| const uint8_t * | b, | ||
| size_t | bStride, | ||
| const uint8_t * | mask, | ||
| size_t | maskStride, | ||
| uint8_t | index, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint64_t * | sum | ||
| ) |
Calculates masked sum of absolute differences (SAD) of two gray 8-bit images.
The result value is computed for points where mask[x, y] equals index:
sum = Σ abs(a[x, y] - b[x, y]), for all (x, y) where mask[x, y] == index.
Both images and mask must have the same width and height.
- Note
- This function has a C++ wrapper Simd::AbsDifferenceSum(const View<A>& a, const View<A>& b, const View<A>& mask, uint8_t index, uint64_t & sum).
- Parameters
-
[in] a - a pointer to pixels data of first image. [in] aStride - a row size of first image. [in] b - a pointer to pixels data of second image. [in] bStride - a row size of second image. [in] mask - a pointer to pixels data of mask image. [in] maskStride - a row size of mask image. [in] index - a mask index. [in] width - an image width. [in] height - an image height. [out] sum - the result sum of absolute difference of two images.
◆ SimdAbsDifferenceSums3x3()
| void SimdAbsDifferenceSums3x3 | ( | const uint8_t * | current, |
| size_t | currentStride, | ||
| const uint8_t * | background, | ||
| size_t | backgroundStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint64_t * | sums | ||
| ) |
Calculates 9 sums of absolute differences for all shifts in 3x3 neighborhood.
Both images must have the same width and height. The image height and width must be equal or greater 3. The sums are computed for the central part of current image (without one-pixel border) and for background image shifted by dx and dy in range [-1, 1]:
sums[(dy + 1)*3 + (dx + 1)] = Σ abs(current[x, y] - background[x + dx, y + dy]),
x = 1..width-2, y = 1..height-2.
Output order is: (-1,-1), (0,-1), (1,-1), (-1,0), (0,0), (1,0), (-1,1), (0,1), (1,1).
- Note
- This function has a C++ wrapper Simd::AbsDifferenceSums3x3(const View<A>& current, const View<A>& background, uint64_t * sums).
- Parameters
-
[in] current - a pointer to pixels data of current image. [in] currentStride - a row size of the current image. [in] background - a pointer to pixels data of the background image. [in] backgroundStride - a row size of the background image. [in] width - an image width. [in] height - an image height. [out] sums - the pointer to buffer with result sums. Buffer size must be equal or greater 9.
◆ SimdAbsDifferenceSums3x3Masked()
| void SimdAbsDifferenceSums3x3Masked | ( | const uint8_t * | current, |
| size_t | currentStride, | ||
| const uint8_t * | background, | ||
| size_t | backgroundStride, | ||
| const uint8_t * | mask, | ||
| size_t | maskStride, | ||
| uint8_t | index, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint64_t * | sums | ||
| ) |
Calculates 9 masked sums of absolute differences for all shifts in 3x3 neighborhood.
The sums are computed only for points where mask[x, y] equals index:
sums[(dy + 1)*3 + (dx + 1)] = Σ abs(current[x, y] - background[x + dx, y + dy]),
for x = 1..width-2, y = 1..height-2 and mask[x, y] == index.
Both images and mask must have the same width and height. The image height and width must be equal or greater 3. Output order is: (-1,-1), (0,-1), (1,-1), (-1,0), (0,0), (1,0), (-1,1), (0,1), (1,1).
- Note
- This function has a C++ wrapper Simd::AbsDifferenceSums3x3(const View<A>& current, const View<A>& background, const View<A>& mask, uint8_t index, uint64_t * sums).
- Parameters
-
[in] current - a pointer to pixels data of current image. [in] currentStride - a row size of the current image. [in] background - a pointer to pixels data of the background image. [in] backgroundStride - a row size of the background image. [in] mask - a pointer to pixels data of mask image. [in] maskStride - a row size of mask image. [in] index - a mask index. [in] width - an image width. [in] height - an image height. [out] sums - the pointer to buffer with result sums. Buffer size must be equal or greater 9.
◆ SimdCosineDistance32f()
| void SimdCosineDistance32f | ( | const float * | a, |
| const float * | b, | ||
| size_t | size, | ||
| float * | distance | ||
| ) |
Calculates the cosine distance between two 32-bit floating-point vectors.
The input vectors must contain size elements. The function writes one scalar result:
aa = Sum(a[i]*a[i]); ab = Sum(a[i]*b[i]); bb = Sum(b[i]*b[i]); distance[0] = 1 - ab/Sqrt(aa*bb);
Both input vectors have to have non-zero Euclidean norm.
- Parameters
-
[in] a - a pointer to the first 32-bit float array. [in] b - a pointer to the second 32-bit float array. [in] size - a number of elements in both input arrays. [out] distance - a pointer to 32-bit float with the cosine distance.
◆ SimdSquaredDifferenceSum()
| void SimdSquaredDifferenceSum | ( | const uint8_t * | a, |
| size_t | aStride, | ||
| const uint8_t * | b, | ||
| size_t | bStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint64_t * | sum | ||
| ) |
Calculates the sum of squared differences for two 8-bit gray images.
All images must have the same width and height. The output sum is initialized to zero inside the function before accumulation.
For every point:
sum[0] += (a[i] - b[i])*(a[i] - b[i]);
- Note
- This function has a C++ wrappers: Simd::SquaredDifferenceSum(const View<A>& a, const View<A>& b, uint64_t & sum).
- Parameters
-
[in] a - a pointer to pixels data of the first image. [in] aStride - a row size of the first image in bytes. [in] b - a pointer to pixels data of the second image. [in] bStride - a row size of the second image in bytes. [in] width - an image width. [in] height - an image height. [out] sum - a pointer to unsigned 64-bit integer value with result sum.
◆ SimdSquaredDifferenceSumMasked()
| void SimdSquaredDifferenceSumMasked | ( | const uint8_t * | a, |
| size_t | aStride, | ||
| const uint8_t * | b, | ||
| size_t | bStride, | ||
| const uint8_t * | mask, | ||
| size_t | maskStride, | ||
| uint8_t | index, | ||
| size_t | width, | ||
| size_t | height, | ||
| uint64_t * | sum | ||
| ) |
Calculates the masked sum of squared differences for two 8-bit gray images.
All images must have the same width and height. The input and mask images must have 8-bit gray format. Only pixels where mask equals index contribute to the result. The output sum is initialized to zero inside the function before accumulation.
For every point:
if(mask[i] == index)
sum[0] += (a[i] - b[i])*(a[i] - b[i]);
- Note
- This function has a C++ wrappers: Simd::SquaredDifferenceSum(const View<A>& a, const View<A>& b, const View<A>& mask, uint8_t index, uint64_t & sum).
- Parameters
-
[in] a - a pointer to pixels data of the first image. [in] aStride - a row size of the first image in bytes. [in] b - a pointer to pixels data of the second image. [in] bStride - a row size of the second image in bytes. [in] mask - a pointer to pixels data of the mask image. [in] maskStride - a row size of the mask image in bytes. [in] index - a mask index that enables accumulation. [in] width - an image width. [in] height - an image height. [out] sum - a pointer to unsigned 64-bit integer value with result sum.
◆ SimdSquaredDifferenceSum32f()
| void SimdSquaredDifferenceSum32f | ( | const float * | a, |
| const float * | b, | ||
| size_t | size, | ||
| float * | sum | ||
| ) |
Calculates the sum of squared differences for two 32-bit float arrays.
All arrays must have the same size. The output sum is overwritten by the calculated value.
For every element:
sum[0] = Sum((a[i] - b[i])*(a[i] - b[i]));
- Parameters
-
[in] a - a pointer to the first array. [in] b - a pointer to the second array. [in] size - a size of arrays. [out] sum - a pointer to the 32-bit float sum of squared differences.
◆ SimdSquaredDifferenceKahanSum32f()
| void SimdSquaredDifferenceKahanSum32f | ( | const float * | a, |
| const float * | b, | ||
| size_t | size, | ||
| float * | sum | ||
| ) |
Calculates the sum of squared differences for two 32-bit float arrays using Kahan summation.
All arrays must have the same size. This variant applies compensated summation to reduce floating-point accumulation error. The output sum is overwritten by the calculated value.
Algorithm pseudo code:
sum[0] = 0; corr = 0;
for(i = 0; i < size; ++i)
{
diff = (a[i] - b[i])*(a[i] - b[i]) - corr;
temp = sum[0] + diff;
corr = (temp - sum[0]) - diff;
sum[0] = temp;
}
- Parameters
-
[in] a - a pointer to the first array. [in] b - a pointer to the second array. [in] size - a size of arrays. [out] sum - a pointer to the 32-bit float sum of squared differences.
◆ AbsDifference()
Gets absolute difference of two gray 8-bit images, pixel by pixel.
Both images must have the same width and height.
- Note
- This function is a C++ wrapper for function SimdAbsDifference.
- Parameters
-
[in] a - a first image. [in] b - a second image. [out] c - a destination image.
◆ AbsDifferenceSum() [1/2]
Gets sum of absolute difference of two gray 8-bit images.
Both images must have the same width and height.
- Note
- This function is a C++ wrapper for function SimdAbsDifferenceSum.
- Parameters
-
[in] a - a first image. [in] b - a second image. [out] sum - the result sum of absolute difference of two images.
◆ AbsDifferenceSum() [2/2]
| void AbsDifferenceSum | ( | const View< A > & | a, |
| const View< A > & | b, | ||
| const View< A > & | mask, | ||
| uint8_t | index, | ||
| uint64_t & | sum | ||
| ) |
Gets sum of absolute difference of two gray 8-bit images based on gray 8-bit mask.
Gets the absolute difference sum for all points when mask[i] == index. Both images and mask must have the same width and height.
- Note
- This function is a C++ wrapper for function SimdAbsDifferenceSumMasked.
- Parameters
-
[in] a - a first image. [in] b - a second image. [in] mask - a mask image. [in] index - a mask index. [out] sum - the result sum of absolute difference of two images.
◆ AbsDifferenceSums3x3() [1/2]
| void AbsDifferenceSums3x3 | ( | const View< A > & | current, |
| const View< A > & | background, | ||
| uint64_t * | sums | ||
| ) |
Gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3.
Both images must have the same width and height. The image height and width must be equal or greater 3. The sums are calculated with central part (indent width = 1) of current image and with part of background image with corresponding shift. The shifts are lain in the range [-1, 1] for axis x and y.
- Note
- This function is a C++ wrapper for function SimdAbsDifferenceSums3x3.
- Parameters
-
[in] current - a current image. [in] background - a background image. [out] sums - the pointer to buffer with result sums. Buffer size must be equal or greater 9.
◆ AbsDifferenceSums3x3() [2/2]
| void AbsDifferenceSums3x3 | ( | const View< A > & | current, |
| const View< A > & | background, | ||
| const View< A > & | mask, | ||
| uint8_t | index, | ||
| uint64_t * | sums | ||
| ) |
Gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3 based on gray 8-bit mask.
Gets the absolute difference sums for all points when mask[i] == index. Both images and mask must have the same width and height. The image height and width must be equal or greater 3. The sums are calculated with central part (indent width = 1) of current image and with part of background image with corresponding shift. The shifts are lain in the range [-1, 1] for axis x and y.
- Note
- This function is a C++ wrapper for function SimdAbsDifferenceSums3x3Masked.
- Parameters
-
[in] current - a current image. [in] background - a background image. [in] mask - a mask image. [in] index - a mask index. [out] sums - the pointer to buffer with result sums. Buffer size must be equal or greater 9.
◆ SquaredDifferenceSum() [1/2]
Calculates sum of squared differences for two 8-bit gray images.
All images must have the same width and height.
For every point:
sum += (a[i] - b[i])*(a[i] - b[i]);
- Note
- This function is a C++ wrapper for function SimdSquaredDifferenceSum.
- Parameters
-
[in] a - a first image. [in] b - a second image. [out] sum - a reference to unsigned 64-bit integer value with result sum.
◆ SquaredDifferenceSum() [2/2]
| void SquaredDifferenceSum | ( | const View< A > & | a, |
| const View< A > & | b, | ||
| const View< A > & | mask, | ||
| uint8_t | index, | ||
| uint64_t & | sum | ||
| ) |
Calculates sum of squared differences for two images with using mask.
All images must have the same width, height and format (8-bit gray).
For every point:
if(mask[i] == index)
sum += (a[i] - b[i])*(a[i] - b[i]);
- Note
- This function is a C++ wrapper for function SimdSquaredDifferenceSumMasked.
- Parameters
-
[in] a - a first image. [in] b - a second image. [in] mask - a mask image. [in] index - a mask index. [out] sum - a reference to unsigned 64-bit integer value with result sum.