Ocean
Ocean::CV::FrameInterpolator Class Reference

This class implements functions interpolating frames and image content. More...

Public Types

enum  InterpolationMethod { IM_INVALID , IM_NEAREST_PIXEL , IM_BILINEAR }
 Definition of individual interpolation methods. More...
 
enum  ResizeMethod {
  RM_INVALID , RM_NEAREST_PIXEL , RM_BILINEAR , RM_NEAREST_PYRAMID_LAYER_11_BILINEAR ,
  RM_NEAREST_PYRAMID_LAYER_14641_BILINEAR , RM_AUTOMATIC = RM_NEAREST_PYRAMID_LAYER_11_BILINEAR
}
 Definition of individual resize methods. More...
 

Static Public Member Functions

static bool resize (Frame &frame, const unsigned int width, const unsigned int height, const ResizeMethod resizeMethod=RM_AUTOMATIC, Worker *worker=nullptr)
 Resizes/rescales a given frame by application of a specified interpolation method. More...
 
static bool resize (const Frame &source, Frame &target, const ResizeMethod resizeMethod=RM_AUTOMATIC, Worker *worker=nullptr)
 Resizes/rescales a given frame by application of a specified interpolation method. More...
 
template<typename T , unsigned int tChannels, ResizeMethod tResizeMethod = RM_AUTOMATIC>
static bool resize (const T *source, T *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
 Resizes/rescales a given 1-plane frame by application of a specified interpolation method. More...
 
static bool affine (const Frame &input, Frame &output, const SquareMatrix3 &input_A_output, const InterpolationMethod interpolationMethod=IM_BILINEAR, const uint8_t *borderColor=nullptr, Worker *worker=nullptr, const PixelPositionI &outputOrigin=PixelPositionI(0, 0))
 Applies an affine transformation to an image (with zipped pixel format). More...
 
static bool homography (const Frame &input, Frame &output, const SquareMatrix3 &input_H_output, const InterpolationMethod interpolationMethod=IM_BILINEAR, const uint8_t *borderColor=nullptr, Worker *worker=nullptr, const PixelPositionI &outputOrigin=PixelPositionI(0, 0))
 Transforms a given input frame (with zipped pixel format) into an output frame (with arbitrary frame dimension) by application of a homography. More...
 

Static Protected Member Functions

template<typename T , unsigned int tChannels>
static bool resize (const T *source, T *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const ResizeMethod resizeMethod, Worker *worker=nullptr)
 Resizes/rescales a given 1-plane frame by application of a specified interpolation method. More...
 

Detailed Description

This class implements functions interpolating frames and image content.

In general, this class is just a thin wrapper around the actual implementation based on the desired interpolation method.
Please be aware that all non-template-based functions of this class are intended for prototyping only.
Binary size can increase significantly when using non-template-based functions as the wrapper will add binary size of every interpolation method.
Thus, in case binary size matters, use the template-based functions directly.
For more details and a visual comparisons of the available image resizing methods see https://facebookresearch.github.io/ocean/docs/images/resizing/

See also
FrameInterpolatorBilinear, FrameInterpolatorNearestPixel.

Member Enumeration Documentation

◆ InterpolationMethod

Definition of individual interpolation methods.

Enumerator
IM_INVALID 

An invalid interpolation method.

IM_NEAREST_PIXEL 

An interpolation applying a nearest pixel (nearest neighbor) lookup.

IM_BILINEAR 

An interpolation applying a bilinear interpolation.

◆ ResizeMethod

Definition of individual resize methods.

Commonly, higher enum values will create better image qualities, while also will need more computational time.

Enumerator
RM_INVALID 

An invalid resize method.

RM_NEAREST_PIXEL 

An interpolation applying a nearest pixel (nearest neighbor) lookup.

RM_BILINEAR 

An interpolation applying a bilinear interpolation.

RM_NEAREST_PYRAMID_LAYER_11_BILINEAR 

A two-step interpolation, first applying a pyramid down sampling with a 11 filtering, followed by bilinear interpolation from pyramid layer to target image.

RM_NEAREST_PYRAMID_LAYER_14641_BILINEAR 

A two-step interpolation, first applying a pyramid down sampling with a 14641 filtering, followed by bilinear interpolation from pyramid layer to target image.

RM_AUTOMATIC 

The resize method with best quality/performance ratio providing high image qualities with good performance values.

Member Function Documentation

◆ affine()

static bool Ocean::CV::FrameInterpolator::affine ( const Frame input,
Frame output,
const SquareMatrix3 input_A_output,
const InterpolationMethod  interpolationMethod = IM_BILINEAR,
const uint8_t *  borderColor = nullptr,
Worker worker = nullptr,
const PixelPositionI outputOrigin = PixelPositionI(0, 0) 
)
static

Applies an affine transformation to an image (with zipped pixel format).

The output frame must have the same pixel format and pixel origin as the input frame, however the dimension (and position) of the output frame can be arbitrary.
This function allows the creation of an output frame fully covering the input frame (if the position and dimension of the output frame covers the transformation of the affine transformation.
The multiplication of the affine transformation with pixel location in the output image yield their location in the input image, i.e., inputPoint = affineTransform * outputPoint.
The parameter 'outputOrigin' applies an additional translation to the provided affine transformation i.e., input_A_output * create_translation_matrix3x3(outputOrigin.x(), outputOrigin.y()).
Please note that here the affine transformation is specified as a 3-by-3 matrix (in contrast to the more commonly used 2-by-3 matrix) and should take of the form:

Rxx  Ryx  Tx
Rxy  Ryy  Ty
 0    0    1

However, this function disregards the last row completely and only uses the top two rows, i.e., the elements a through f. Information: This function is the equivalent to OpenCV's cv::warpAffine().
Note: For applications running on mobile devices, in order to keep the impact on binary size to a minimum please prefer a specialized transformation function (those that work on image pointers instead of Frame instances).

Parameters
inputThe input frame that will be transformed, must be valid
outputThe resulting frame after applying the affine transformation to the input frame; pixel format and pixel origin must be identical to input frame; memory of output frame must be allocated by the caller
input_A_outputThe affine transform used to transform the given input frame, transforming points defined in the output frame into points defined in the input frame
interpolationMethodThe interpolation method to be used, must be either IM_BILINEAR or IM_NEAREST_PIXEL
borderColorColor of undefined pixel positions, the size of the buffer must match to the number of channels, nullptr to assign 0x00 to each channel
workerOptional worker object to distribute the computational load
outputOriginThe origin of the output frame defining the global position of the output frame's pixel coordinate (0, 0), with range (-infinity, infinity)x(-infinity, infinity)
Returns
True, if succeeded

◆ homography()

static bool Ocean::CV::FrameInterpolator::homography ( const Frame input,
Frame output,
const SquareMatrix3 input_H_output,
const InterpolationMethod  interpolationMethod = IM_BILINEAR,
const uint8_t *  borderColor = nullptr,
Worker worker = nullptr,
const PixelPositionI outputOrigin = PixelPositionI(0, 0) 
)
static

Transforms a given input frame (with zipped pixel format) into an output frame (with arbitrary frame dimension) by application of a homography.

The output frame must have the same pixel format and pixel origin as the input frame, however the dimension (and position) of the output frame can be arbitrary.
This function allows the creation of an output frame fully covering the input frame (if the position and dimension of the output frame covers the transformation of the homography.
The homography given defines the transformation of output pixels to input pixels (inputPoint = homography * outputPoint).
The 'outputOrigin' parameter simply applies an additional translation onto the provided homography i.e., homography * create_translation_matrix3x3(outputOrigin.x(), outputOrigin.y()).
Information: This function is the equivalent to OpenCV's cv::warpPerspective().

Parameters
inputThe input frame that will be transformed, must be valid
outputThe output frame resulting by application of the given homography, with same pixel format and pixel origin as the input frame, must be valid
input_H_outputThe homography used to transform the given input frame, transforming points defined in the output frame into points defined in the input frame
interpolationMethodThe interpolation method to be used, must be either IM_BILINEAR or IM_NEAREST_PIXEL
borderColorColor of undefined pixel positions, the size of the buffer must match to the number of channels, nullptr to assign 0x00 to each channel
workerOptional worker object to distribute the computational load
outputOriginThe origin of the output frame defining the global position of the output frame's pixel coordinate (0, 0), with range (-infinity, infinity)x(-infinity, infinity)
Returns
True, if succeeded

◆ resize() [1/4]

static bool Ocean::CV::FrameInterpolator::resize ( const Frame source,
Frame target,
const ResizeMethod  resizeMethod = RM_AUTOMATIC,
Worker worker = nullptr 
)
static

Resizes/rescales a given frame by application of a specified interpolation method.

Parameters
sourceThe source frame to resize, must not have a packed pixel format, must be valid
targetResulting target frame with identical frame pixel format and pixel origin as the source frame, must be valid
resizeMethodThe resize method to be used
workerOptional worker object used for load distribution, must be valid
Returns
True, if the frame could be resized
See also
FrameType::formatIsPacked().

◆ resize() [2/4]

template<typename T , unsigned int tChannels>
static bool Ocean::CV::FrameInterpolator::resize ( const T *  source,
T *  target,
const unsigned int  sourceWidth,
const unsigned int  sourceHeight,
const unsigned int  targetWidth,
const unsigned int  targetHeight,
const unsigned int  sourcePaddingElements,
const unsigned int  targetPaddingElements,
const ResizeMethod  resizeMethod,
Worker worker = nullptr 
)
staticprotected

Resizes/rescales a given 1-plane frame by application of a specified interpolation method.

This template-based implementation ensures that the binary impact is as small as possible.

Parameters
sourceThe source frame buffer to resize, must be valid
targetThe target frame buffer, must be valid
sourceWidthWidth of the source frame in pixel, with range [1, infinity)
sourceHeightHeight of the source frame in pixel, with range [1, infinity)
targetWidthWidth of the target frame in pixel, with range [1, infinity)
targetHeightHeight of the target frame in pixel, with range [1, infinity)
sourcePaddingElementsOptional padding at the end of each source row in elements, with range [0, infinity)
targetPaddingElementsOptional padding at the end of each target row in elements, with range [0, infinity)
resizeMethodThe resize method to be used
workerOptional worker object used for load distribution
Returns
True, if the frame could be resized
Template Parameters
TData type of each pixel channel, e.g., 'uint8_t', 'float'
tChannelsNumber of channels of the frame, with range [1, infinity)

◆ resize() [3/4]

template<typename T , unsigned int tChannels, FrameInterpolator::ResizeMethod tResizeMethod>
bool Ocean::CV::FrameInterpolator::resize ( const T *  source,
T *  target,
const unsigned int  sourceWidth,
const unsigned int  sourceHeight,
const unsigned int  targetWidth,
const unsigned int  targetHeight,
const unsigned int  sourcePaddingElements,
const unsigned int  targetPaddingElements,
Worker worker = nullptr 
)
static

Resizes/rescales a given 1-plane frame by application of a specified interpolation method.

This template-based implementation ensures that the binary impact is as small as possible.

Parameters
sourceThe source frame buffer to resize, must be valid
targetThe target frame buffer, must be valid
sourceWidthWidth of the source frame in pixel, with range [1, infinity)
sourceHeightHeight of the source frame in pixel, with range [1, infinity)
targetWidthWidth of the target frame in pixel, with range [1, infinity)
targetHeightHeight of the target frame in pixel, with range [1, infinity)
sourcePaddingElementsOptional padding at the end of each source row in elements, with range [0, infinity)
targetPaddingElementsOptional padding at the end of each target row in elements, with range [0, infinity)
workerOptional worker object used for load distribution
Returns
True, if the frame could be resized
Template Parameters
TData type of each pixel channel, e.g., 'uint8_t', 'float'
tChannelsNumber of channels of the frame, with range [1, infinity)
tResizeMethodThe resize method to be used

◆ resize() [4/4]

static bool Ocean::CV::FrameInterpolator::resize ( Frame frame,
const unsigned int  width,
const unsigned int  height,
const ResizeMethod  resizeMethod = RM_AUTOMATIC,
Worker worker = nullptr 
)
static

Resizes/rescales a given frame by application of a specified interpolation method.

Parameters
frameThe frame to resize, must not have a packed pixel format, must be valid
widthThe width of the resized frame in pixel, with range [1, infinity)
heightThe height of the resized frame in pixel, with range [1, infinity)
resizeMethodThe resize method to be used
workerOptional worker object used for load distribution, must be valid
Returns
True, if the frame could be resized
See also
FrameType::formatIsPacked().

The documentation for this class was generated from the following file: