Compute Library
 23.11
warp_helpers.h File Reference
#include "helpers.h"

Go to the source code of this file.

Functions

const float8 clamp_to_border_with_size (float8 coords, const float width, const float height, const float border_size)
 Clamps the given coordinates to the borders according to the border size. More...
 
const float8 clamp_to_border (float8 coords, const float width, const float height)
 Clamps the given coordinates to the borders. More...
 
const DATA_TYPE4 read_texels4 (const Image *in, const int8 coords)
 Reads four texels from the input image. More...
 
const float8 get_neighbour_coords (const float2 coord)
 Given a texel coordinates this function will return the following array of coordinates: [ P, right neighbour, below neighbour, below right neighbour ]. More...
 
const DATA_TYPE4 bilinear_interpolate_with_border (const Image *in, const float8 coords, const float width, const float height, const float border_size)
 Computes the bilinear interpolation for each set of coordinates in the vector coords and returns the values. More...
 
const DATA_TYPE4 bilinear_interpolate (const Image *in, const float8 coords, const float width, const float height)
 Computes the bilinear interpolation for each set of coordinates in the vector coords and returns the values. More...
 

Function Documentation

◆ bilinear_interpolate()

const DATA_TYPE4 bilinear_interpolate ( const Image in,
const float8  coords,
const float  width,
const float  height 
)
inline

Computes the bilinear interpolation for each set of coordinates in the vector coords and returns the values.

Parameters
[in]inPointer to the source image.
[in]coordsVector of four 2D coordinates. Even pos is x and odd y.
[in]widthWidth of the image
[in]heightHeight of the image

Definition at line 134 of file warp_helpers.h.

135 {
136  return bilinear_interpolate_with_border(in, coords, width, height, 1);
137 }

References bilinear_interpolate_with_border().

◆ bilinear_interpolate_with_border()

const DATA_TYPE4 bilinear_interpolate_with_border ( const Image in,
const float8  coords,
const float  width,
const float  height,
const float  border_size 
)
inline

Computes the bilinear interpolation for each set of coordinates in the vector coords and returns the values.

Parameters
[in]inPointer to the source image.
[in]coordsVector of four 2D coordinates. Even pos is x and odd y.
[in]widthWidth of the image
[in]heightHeight of the image
[in]border_sizeBorder size

Definition at line 91 of file warp_helpers.h.

93 {
94  // If any of the 4 texels is out of the image's boundaries we use the border value (REPLICATE or CONSTANT) for any texel out of the image.
95 
96  // Sets the 4x4 coordinates for each of the four input texels
97  const float8 fc = floor(coords);
98  const float16 c1 =
99  (float16)(clamp_to_border_with_size(get_neighbour_coords((float2)(fc.s0, fc.s1)), width, height, border_size),
100  clamp_to_border_with_size(get_neighbour_coords((float2)(fc.s2, fc.s3)), width, height, border_size));
101  const float16 c2 =
102  (float16)(clamp_to_border_with_size(get_neighbour_coords((float2)(fc.s4, fc.s5)), width, height, border_size),
103  clamp_to_border_with_size(get_neighbour_coords((float2)(fc.s6, fc.s7)), width, height, border_size));
104 
105  // Loads the values from the input image
106  const float16 t = (float16)(
107  /* tl, tr, bl, br */
108  *((__global DATA_TYPE *)offset(in, c1.s0, c1.s1)), *((__global DATA_TYPE *)offset(in, c1.s2, c1.s3)),
109  *((__global DATA_TYPE *)offset(in, c1.s4, c1.s5)), *((__global DATA_TYPE *)offset(in, c1.s6, c1.s7)),
110  *((__global DATA_TYPE *)offset(in, c1.s8, c1.s9)), *((__global DATA_TYPE *)offset(in, c1.sa, c1.sb)),
111  *((__global DATA_TYPE *)offset(in, c1.sc, c1.sd)), *((__global DATA_TYPE *)offset(in, c1.se, c1.sf)),
112  *((__global DATA_TYPE *)offset(in, c2.s0, c2.s1)), *((__global DATA_TYPE *)offset(in, c2.s2, c2.s3)),
113  *((__global DATA_TYPE *)offset(in, c2.s4, c2.s5)), *((__global DATA_TYPE *)offset(in, c2.s6, c2.s7)),
114  *((__global DATA_TYPE *)offset(in, c2.s8, c2.s9)), *((__global DATA_TYPE *)offset(in, c2.sa, c2.sb)),
115  *((__global DATA_TYPE *)offset(in, c2.sc, c2.sd)), *((__global DATA_TYPE *)offset(in, c2.se, c2.sf)));
116  const float8 a = coords - fc;
117  const float8 b = ((float8)(1.f)) - a;
118  const float4 fr =
119  (float4)(((t.s0 * b.s0 * b.s1) + (t.s1 * a.s0 * b.s1) + (t.s2 * b.s0 * a.s1) + (t.s3 * a.s0 * a.s1)),
120  ((t.s4 * b.s2 * b.s3) + (t.s5 * a.s2 * b.s3) + (t.s6 * b.s2 * a.s3) + (t.s7 * a.s2 * a.s3)),
121  ((t.s8 * b.s4 * b.s5) + (t.s9 * a.s4 * b.s5) + (t.sa * b.s4 * a.s5) + (t.sb * a.s4 * a.s5)),
122  ((t.sc * b.s6 * b.s7) + (t.sd * a.s6 * b.s7) + (t.se * b.s6 * a.s7) + (t.sf * a.s6 * a.s7)));
123  return CONVERT(fr, VEC_DATA_TYPE(DATA_TYPE, 4));
124 }

References arm_compute::test::validation::b, clamp_to_border_with_size(), CONVERT, get_neighbour_coords(), offset(), tf_frozen_model_extractor::t, and VEC_DATA_TYPE.

Referenced by bilinear_interpolate().

◆ clamp_to_border()

const float8 clamp_to_border ( float8  coords,
const float  width,
const float  height 
)
inline

Clamps the given coordinates to the borders.

Parameters
[in]coordsVector of 2D coordinates to clamp. Even positions are X coords, odd positions are Y coords.
[in]widthWidth of the image
[in]heightHeight of the image

Definition at line 50 of file warp_helpers.h.

51 {
52  return clamp_to_border_with_size(coords, width, height, 1);
53 }

References clamp_to_border_with_size().

◆ clamp_to_border_with_size()

const float8 clamp_to_border_with_size ( float8  coords,
const float  width,
const float  height,
const float  border_size 
)
inline

Clamps the given coordinates to the borders according to the border size.

Parameters
[in]coordsVector of 2D coordinates to clamp. Even positions are X coords, odd positions are Y coords.
[in]widthWidth of the image
[in]heightHeight of the image
[in]border_sizeBorder size of the image

Definition at line 35 of file warp_helpers.h.

36 {
37  const float4 clamped_x = clamp(coords.even, 0.0f - border_size, width - 1 + border_size);
38  const float4 clamped_y = clamp(coords.odd, 0.0f - border_size, height - 1 + border_size);
39  return (float8)(clamped_x.s0, clamped_y.s0, clamped_x.s1, clamped_y.s1, clamped_x.s2, clamped_y.s2, clamped_x.s3,
40  clamped_y.s3);
41 }

References arm_compute::utility::clamp().

Referenced by bilinear_interpolate_with_border(), and clamp_to_border().

◆ get_neighbour_coords()

const float8 get_neighbour_coords ( const float2  coord)
inline

Given a texel coordinates this function will return the following array of coordinates: [ P, right neighbour, below neighbour, below right neighbour ].

Note
No checks to see if the coordinates are out of the image are done here.
Parameters
[in]coordInput coordinates
Returns
vector of 8 floats with the coordinates, even positions are x and odd y.

Definition at line 77 of file warp_helpers.h.

78 {
79  return (float8)(/*tl*/ coord.s0, coord.s1, /*tr*/ coord.s0 + 1, coord.s1, /*bl*/ coord.s0, coord.s1 + 1,
80  /*br*/ coord.s0 + 1, coord.s1 + 1);
81 }

Referenced by bilinear_interpolate_with_border().

◆ read_texels4()

const DATA_TYPE4 read_texels4 ( const Image in,
const int8  coords 
)
inline

Reads four texels from the input image.

The coords vector is used to determine which texels to be read.

Parameters
[in]inPointer to the source image.
[in]coordsVector of coordinates to be read from the image.

Definition at line 60 of file warp_helpers.h.

61 {
62  return (VEC_DATA_TYPE(DATA_TYPE, 4))(*((__global DATA_TYPE *)offset(in, coords.s0, coords.s1)),
63  *((__global DATA_TYPE *)offset(in, coords.s2, coords.s3)),
64  *((__global DATA_TYPE *)offset(in, coords.s4, coords.s5)),
65  *((__global DATA_TYPE *)offset(in, coords.s6, coords.s7)));
66 }

References offset(), and VEC_DATA_TYPE.

get_neighbour_coords
const float8 get_neighbour_coords(const float2 coord)
Given a texel coordinates this function will return the following array of coordinates: [ P,...
Definition: warp_helpers.h:77
VEC_DATA_TYPE
#define VEC_DATA_TYPE(type, size)
Definition: helpers.h:764
arm_compute::utility::clamp
DataType clamp(const DataType &n, const DataType &lower=std::numeric_limits< RangeType >::lowest(), const DataType &upper=std::numeric_limits< RangeType >::max())
Performs clamping among a lower and upper value.
Definition: Utility.h:102
clamp_to_border_with_size
const float8 clamp_to_border_with_size(float8 coords, const float width, const float height, const float border_size)
Clamps the given coordinates to the borders according to the border size.
Definition: warp_helpers.h:35
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1128
arm_compute::test::validation::b
SimpleTensor< float > b
Definition: DFT.cpp:157
CONVERT
#define CONVERT(x, type)
Definition: helpers.h:767
bilinear_interpolate_with_border
const DATA_TYPE4 bilinear_interpolate_with_border(const Image *in, const float8 coords, const float width, const float height, const float border_size)
Computes the bilinear interpolation for each set of coordinates in the vector coords and returns the ...
Definition: warp_helpers.h:91
tf_frozen_model_extractor.t
t
Definition: tf_frozen_model_extractor.py:49