Functions for image shifting. More...
Functions | |
| SIMD_API void | SimdShiftBilinear (const uint8_t *src, size_t srcStride, size_t width, size_t height, size_t channelCount, const uint8_t *bkg, size_t bkgStride, const double *shiftX, const double *shiftY, size_t cropLeft, size_t cropTop, size_t cropRight, size_t cropBottom, uint8_t *dst, size_t dstStride) |
| Shifts an image inside a crop rectangle with bilinear interpolation. More... | |
| SIMD_API void * | SimdShiftDetectorInitBuffers (size_t bkgWidth, size_t bkgHeight, size_t levelCount, SimdShiftDetectorTextureType textureType, SimdShiftDetectorDifferenceType differenceType) |
| Creates a shift detector context and its image pyramids. More... | |
| SIMD_API void | SimdShiftDetectorSetBackground (void *context, const uint8_t *bkg, size_t bkgStride, SimdBool makeCopy) |
| Sets the background image for a shift detector context. More... | |
| SIMD_API SimdBool | SimdShiftDetectorEstimate (void *context, const uint8_t *curr, size_t currStride, size_t currWidth, size_t currHeight, size_t initShiftX, size_t initShiftY, size_t maxShiftX, size_t maxShiftY, const double *hiddenAreaPenalty, ptrdiff_t regionAreaMin) |
| Estimates translation of a current image relative to the background. More... | |
| SIMD_API void | SimdShiftDetectorGetShift (const void *context, ptrdiff_t *shift, double *refinedShift, double *stability, double *correlation) |
| Gets shift and quality values estimated by SimdShiftDetectorEstimate. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ShiftBilinear (const View< A > &src, const View< A > &bkg, const Point< double > &shift, const Rectangle< ptrdiff_t > &crop, View< A > &dst) |
| Performs shifting of input image with using bilinear interpolation. More... | |
Detailed Description
Functions for image shifting.
Enumeration Type Documentation
◆ SimdShiftDetectorTextureType
Describes types of texture which used to find correlation between background and current image in function SimdShiftDetectorInitBuffers.
| Enumerator | |
|---|---|
| SimdShiftDetectorTextureGray | Original grayscale image. |
| SimdShiftDetectorTextureGrad | Saturated sum of absolute gradients along X and Y axes. |
◆ SimdShiftDetectorDifferenceType
Describes types of function which used to find correlation between background and current image in function SimdShiftDetectorInitBuffers.
| Enumerator | |
|---|---|
| SimdShiftDetectorAbsDifference | Sum of absolute differences of points of two images. |
| SimdShiftDetectorSquaredDifference | Sum of squared differences of points of two images. |
Function Documentation
◆ SimdShiftBilinear()
| void SimdShiftBilinear | ( | const uint8_t * | src, |
| size_t | srcStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| size_t | channelCount, | ||
| const uint8_t * | bkg, | ||
| size_t | bkgStride, | ||
| const double * | shiftX, | ||
| const double * | shiftY, | ||
| size_t | cropLeft, | ||
| size_t | cropTop, | ||
| size_t | cropRight, | ||
| size_t | cropBottom, | ||
| uint8_t * | dst, | ||
| size_t | dstStride | ||
| ) |
Shifts an image inside a crop rectangle with bilinear interpolation.
All images must have the same width, height and number of 8-bit channels. The function first copies the area outside [cropLeft, cropRight) x [cropTop, cropBottom) from src to dst. Inside the crop rectangle it shifts src by (shiftX[0], shiftY[0]) and writes bilinear interpolated pixels to dst. Pixels uncovered by the shift are copied from bkg; border pixels where source and background overlap are mixed by the same bilinear weights. The shift values must be smaller than the crop rectangle width and height.
- Note
- This function has a C++ wrappers: Simd::ShiftBilinear(const View<A> & src, const View<A> & bkg, const Point<double> & shift, const Rectangle<ptrdiff_t> & crop, View<A> & dst).
- Parameters
-
[in] src - a pointer to pixels data of the foreground input image. [in] srcStride - a row size of the input image in bytes. [in] width - an image width. [in] height - an image height. [in] channelCount - a number of 8-bit channels per pixel. [in] bkg - a pointer to pixels data of the background input image. [in] bkgStride - a row size of the background image in bytes. [in] shiftX - a pointer to the image shift along the X axis. [in] shiftY - a pointer to the image shift along the Y axis. [in] cropLeft - a left side of the crop rectangle. [in] cropTop - a top side of the crop rectangle. [in] cropRight - a right side of the crop rectangle. [in] cropBottom - a bottom side of the crop rectangle. [out] dst - a pointer to pixels data of the output image. [in] dstStride - a row size of the output image in bytes.
◆ SimdShiftDetectorInitBuffers()
| void * SimdShiftDetectorInitBuffers | ( | size_t | bkgWidth, |
| size_t | bkgHeight, | ||
| size_t | levelCount, | ||
| SimdShiftDetectorTextureType | textureType, | ||
| SimdShiftDetectorDifferenceType | differenceType | ||
| ) |
Creates a shift detector context and its image pyramids.
The detector is used to estimate translation of a current gray image relative to a background image. It stores background/current pyramids of levelCount levels with base size bkgWidth by bkgHeight. The textureType parameter selects whether matching is done on the original gray image or on the saturated sum of absolute X/Y gradients. The differenceType parameter selects the difference metric minimized during search.
- Note
- This function used in class Simd::ShiftDetector.
- Parameters
-
[in] bkgWidth - a width of the background image. [in] bkgHeight - a height of the background image. [in] levelCount - the number of levels in the internal image pyramids used to find shift. [in] textureType - a type of texture used to detect shift (see SimdShiftDetectorTextureType). [in] differenceType - a difference metric used to detect shift (see SimdShiftDetectorDifferenceType).
- Returns
- a pointer to shift detector context. On error it returns NULL. This pointer is used by functions SimdShiftDetectorSetBackground, SimdShiftDetectorEstimate and SimdShiftDetectorGetShift. It must be released with function SimdRelease.
◆ SimdShiftDetectorSetBackground()
| void SimdShiftDetectorSetBackground | ( | void * | context, |
| const uint8_t * | bkg, | ||
| size_t | bkgStride, | ||
| SimdBool | makeCopy | ||
| ) |
Sets the background image for a shift detector context.
The background image size is fixed by SimdShiftDetectorInitBuffers. If the detector texture type is SimdShiftDetectorTextureGray and makeCopy is SimdFalse, the context stores a view of the external background buffer and the caller must keep it valid. Otherwise the background data or its gradient texture is stored inside the context. After setting the base image the function builds the internal 2x downsampled pyramid.
- Note
- This function used in class Simd::ShiftDetector.
- Parameters
-
[in] context - a shift detector context. It must be created by function SimdShiftDetectorInitBuffers and released by function SimdRelease. [in] bkg - a pointer to pixels data of the 8-bit gray background image. [in] bkgStride - a row size of the background image in bytes. [in] makeCopy - a flag to copy the gray background data into the context.
◆ SimdShiftDetectorEstimate()
| SimdBool SimdShiftDetectorEstimate | ( | void * | context, |
| const uint8_t * | curr, | ||
| size_t | currStride, | ||
| size_t | currWidth, | ||
| size_t | currHeight, | ||
| size_t | initShiftX, | ||
| size_t | initShiftY, | ||
| size_t | maxShiftX, | ||
| size_t | maxShiftY, | ||
| const double * | hiddenAreaPenalty, | ||
| ptrdiff_t | regionAreaMin | ||
| ) |
Estimates translation of a current image relative to the background.
The background must be set by SimdShiftDetectorSetBackground before this call. The current image is interpreted as an 8-bit gray image. The rectangle [initShiftX, initShiftX + currWidth) x [initShiftY, initShiftY + currHeight) defines the current image position in background coordinates before applying the estimated shift. The search is performed from coarse to fine pyramid levels and is limited by maxShiftX and maxShiftY. hiddenAreaPenalty[0] penalizes candidate shifts that hide part of the initial region outside the background; regionAreaMin selects the finest pyramid levels whose search region area is large enough. On success, call SimdShiftDetectorGetShift to read the result.
- Note
- This function used in class Simd::ShiftDetector.
- Parameters
-
[in] context - a shift detector context. It must be created by function SimdShiftDetectorInitBuffers and released by function SimdRelease. [in] curr - a pointer to pixels data of the 8-bit gray current image. [in] currStride - a row size of the current image in bytes. [in] currWidth - a width of the current image. [in] currHeight - a height of the current image. [in] initShiftX - an initial X position of current image in background coordinates. [in] initShiftY - an initial Y position of current image in background coordinates. [in] maxShiftX - maximal absolute shift along X axis. [in] maxShiftY - maximal absolute shift along Y axis. [in] hiddenAreaPenalty - a pointer to a penalty factor for shifts near/outside the background border. [in] regionAreaMin - a minimal search-region area used to choose active pyramid levels.
- Returns
- a result of shift estimation (SimdTrue or SimdFalse). On success use SimdShiftDetectorGetShift to get shift and other parameters.
◆ SimdShiftDetectorGetShift()
| void SimdShiftDetectorGetShift | ( | const void * | context, |
| ptrdiff_t * | shift, | ||
| double * | refinedShift, | ||
| double * | stability, | ||
| double * | correlation | ||
| ) |
Gets shift and quality values estimated by SimdShiftDetectorEstimate.
Any output pointer can be NULL. The integer shift is the best discrete translation at the base pyramid level. The refined shift adds sub-pixel refinement estimated from the 3x3 neighborhood of difference values. Stability characterizes how well the minimum is separated from its neighborhood. Correlation is derived from the best average difference and is close to 1 for similar images.
- Note
- This function used in class Simd::ShiftDetector.
- Parameters
-
[in] context - a shift detector context. It must be created by function SimdShiftDetectorInitBuffers and released by function SimdRelease. [out] shift - a pointer to array[2] that receives integer X and Y shift. Can be NULL. [out] refinedShift - a pointer to array[2] that receives sub-pixel X and Y shift. Can be NULL. [out] stability - a pointer to a value that receives stability of the found shift. Can be NULL. [out] correlation - a pointer to a value that receives correlation of background and current image. Can be NULL.
◆ ShiftBilinear()
| void ShiftBilinear | ( | const View< A > & | src, |
| const View< A > & | bkg, | ||
| const Point< double > & | shift, | ||
| const Rectangle< ptrdiff_t > & | crop, | ||
| View< A > & | dst | ||
| ) |
Performs shifting of input image with using bilinear interpolation.
All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).
- Note
- This function is a C++ wrapper for function SimdShiftBilinear.
- Parameters
-
[in] src - a foreground input image. [in] bkg - a background input image. [in] shift - an image shift. [in] crop - a crop rectangle. [out] dst - an output image.