8 #ifndef META_OCEAN_CV_FRAME_INTERPOLATOR_H
9 #define META_OCEAN_CV_FRAME_INTERPOLATOR_H
69 RM_AUTOMATIC = RM_NEAREST_PYRAMID_LAYER_11_BILINEAR
84 static bool resize(
Frame& frame,
const unsigned int width,
const unsigned int height,
const ResizeMethod resizeMethod = RM_AUTOMATIC,
Worker* worker =
nullptr);
114 template <
typename T,
unsigned int tChannels, ResizeMethod tResizeMethod = RM_AUTOMATIC>
115 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);
180 template <
typename T,
unsigned int tChannels>
181 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);
184 template <
typename T,
unsigned int tChannels, FrameInterpolator::ResizeMethod tResizeMethod>
185 bool 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)
187 static_assert(tChannels >= 1u,
"Invalid channel number!");
188 static_assert(tResizeMethod !=
RM_INVALID,
"Invalid resize method!");
191 ocean_assert(source !=
nullptr && target !=
nullptr);
192 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
193 ocean_assert(targetWidth != 0u && targetHeight != 0u);
195 if (source ==
nullptr || target ==
nullptr || sourceWidth == 0u || sourceHeight == 0u || targetWidth == 0u || targetHeight == 0u)
200 if (sourceWidth == targetWidth && sourceHeight == targetHeight)
202 const bool result = CV::FrameConverter::subFrame<T>(source, target, sourceWidth, sourceHeight, sourceWidth, sourceHeight, tChannels, 0u, 0u, 0u, 0u, sourceWidth, sourceHeight, sourcePaddingElements, targetPaddingElements);
203 ocean_assert(result);
210 FrameInterpolatorNearestPixel::resize<T, tChannels>(source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, worker);
216 FrameInterpolatorBilinear::resize<T, tChannels>(source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, worker);
222 if constexpr (std::is_same<T, uint8_t>::value ==
false)
224 ocean_assert(
false &&
"Missing implementation!");
228 const uint8_t*
const source_u8 = (
const uint8_t*)(source);
229 uint8_t*
const target_u8 = (uint8_t*)(target);
231 if (sourceWidth / 2u == targetWidth && sourceHeight / 2u == targetHeight)
245 else if (targetWidth < sourceWidth && targetHeight < sourceHeight)
247 ocean_assert(targetWidth > 0u && targetHeight >= 0u);
248 const unsigned int invalidCoarsestWidth = targetWidth - 1u;
249 const unsigned int invalidCoarsestHeight = targetHeight - 1u;
251 unsigned int coarsestLayerWidth = 0u;
252 unsigned int coarsestLayerHeight = 0u;
254 unsigned int layers =
CV::FramePyramid::idealLayers(sourceWidth, sourceHeight, invalidCoarsestWidth, invalidCoarsestHeight, &coarsestLayerWidth, &coarsestLayerHeight);
258 ocean_assert(
false &&
"This should never happen!");
262 if (coarsestLayerWidth == targetWidth && coarsestLayerHeight == targetHeight)
266 ocean_assert(layers >= 2u);
278 framePyramid =
FramePyramid(source_u8, sourceWidth, sourceHeight, tChannels, anyPixelOrientation, layers, sourcePaddingElements,
false , worker);
288 ocean_assert(
false &&
"This should never happen!");
294 FrameInterpolatorBilinear::resize<T, tChannels>(coarsestPyramidLayer.
constdata<T>(), target, coarsestPyramidLayer.
width(), coarsestPyramidLayer.
height(), targetWidth, targetHeight, coarsestPyramidLayer.
paddingElements(), targetPaddingElements, worker);
299 FrameInterpolatorBilinear::resize<T, tChannels>(source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, worker);
303 ocean_assert(
false &&
"Invalid interpolation type!");
This class implements functions interpolating frames and image content.
Definition: FrameInterpolator.h:36
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).
ResizeMethod
Definition of individual resize methods.
Definition: FrameInterpolator.h:57
@ RM_NEAREST_PIXEL
An interpolation applying a nearest pixel (nearest neighbor) lookup.
Definition: FrameInterpolator.h:61
@ RM_BILINEAR
An interpolation applying a bilinear interpolation.
Definition: FrameInterpolator.h:63
@ RM_NEAREST_PYRAMID_LAYER_11_BILINEAR
A two-step interpolation, first applying a pyramid down sampling with a 11 filtering,...
Definition: FrameInterpolator.h:65
@ RM_INVALID
An invalid resize method.
Definition: FrameInterpolator.h:59
@ RM_NEAREST_PYRAMID_LAYER_14641_BILINEAR
A two-step interpolation, first applying a pyramid down sampling with a 14641 filtering,...
Definition: FrameInterpolator.h:67
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.
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 ...
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.
InterpolationMethod
Definition of individual interpolation methods.
Definition: FrameInterpolator.h:43
@ IM_NEAREST_PIXEL
An interpolation applying a nearest pixel (nearest neighbor) lookup.
Definition: FrameInterpolator.h:47
@ IM_INVALID
An invalid interpolation method.
Definition: FrameInterpolator.h:45
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.
This class implements a frame pyramid.
Definition: FramePyramid.h:37
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidthOrHeight, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer.
bool isValid() const
Returns whether this pyramid holds at least one frame layer.
Definition: FramePyramid.h:863
@ DM_FILTER_14641
Down sampling is realized by a 5x5 Gaussian filter.
Definition: FramePyramid.h:72
const Frame & coarsestLayer() const
Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
Definition: FramePyramid.h:747
static void downsampleByTwo8BitPerChannel11(const uint8_t *source, uint8_t *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int channels, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Reduces the resolution of a given frame by two, applying a 1-1 downsampling.
Definition: FrameShrinker.h:508
static void downsampleByTwo8BitPerChannel14641(const uint8_t *const source, uint8_t *const target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int channels, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Reduces the resolution of a given frame by two, applying a 1-4-6-4-1 downsampling.
Definition: FrameShrinker.h:561
This class implements a 2D pixel position with pixel precision.
Definition: PixelPosition.h:65
This class implements Ocean's image class.
Definition: Frame.h:1792
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition: Frame.h:4168
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition: Frame.h:4042
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
PixelOrigin
Defines different types of frame origin positions.
Definition: Frame.h:1046
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1050
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3148
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
PixelPositionT< int > PixelPositionI
Definition of a PixelPosition object with a data type allowing positive and negative coordinate value...
Definition: PixelPosition.h:41
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15