Compute Library
 21.11
arm_compute::scale_helpers Namespace Reference

Functions

uint8_t delta_bilinear_c1_quantized (const uint8_t *pixel_ptr, size_t stride, float dx, float dy, UniformQuantizationInfo iq_info, UniformQuantizationInfo oq_info)
 Computes bilinear interpolation for quantized input and output, using the pointer to the top-left pixel and the pixel's distance between the real coordinates and the smallest following integer coordinates. More...
 
int8_t delta_bilinear_c1_quantized (const int8_t *pixel_ptr, size_t stride, float dx, float dy, UniformQuantizationInfo iq_info, UniformQuantizationInfo oq_info)
 Computes bilinear interpolation for quantized input and output, using the pointer to the top-left pixel and the pixel's distance between the real coordinates and the smallest following integer coordinates. More...
 
uint8_t pixel_area_c1u8_clamp (const uint8_t *first_pixel_ptr, size_t stride, size_t width, size_t height, float wr, float hr, int x, int y)
 Return the pixel at (x,y) using area interpolation by clamping when out of borders. More...
 
float delta_bilinear (float a00, float a01, float a10, float a11, float dx_val, float dy_val)
 Computes bilinear interpolation using the top-left, top-right, bottom-left, bottom-right pixels and the pixel's distance between the real coordinates and the smallest following integer coordinates. More...
 

Function Documentation

◆ delta_bilinear()

float arm_compute::scale_helpers::delta_bilinear ( float  a00,
float  a01,
float  a10,
float  a11,
float  dx_val,
float  dy_val 
)
inline

Computes bilinear interpolation using the top-left, top-right, bottom-left, bottom-right pixels and the pixel's distance between the real coordinates and the smallest following integer coordinates.

Parameters
[in]a00The top-left pixel value.
[in]a01The top-right pixel value.
[in]a10The bottom-left pixel value.
[in]a11The bottom-right pixel value.
[in]dx_valPixel's distance between the X real coordinate and the smallest X following integer
[in]dy_valPixel's distance between the Y real coordinate and the smallest Y following integer
Note
dx and dy must be in the range [0, 1.0]
Returns
The bilinear interpolated pixel value

Definition at line 186 of file ScaleHelpers.h.

Referenced by CpuScaleKernel::configure().

187 {
188  const float dx1_val = 1.0f - dx_val;
189  const float dy1_val = 1.0f - dy_val;
190 
191  const float w1 = dx1_val * dy1_val;
192  const float w2 = dx_val * dy1_val;
193  const float w3 = dx1_val * dy_val;
194  const float w4 = dx_val * dy_val;
195  return a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
196 }

◆ delta_bilinear_c1_quantized() [1/2]

uint8_t arm_compute::scale_helpers::delta_bilinear_c1_quantized ( const uint8_t *  pixel_ptr,
size_t  stride,
float  dx,
float  dy,
UniformQuantizationInfo  iq_info,
UniformQuantizationInfo  oq_info 
)
inline

Computes bilinear interpolation for quantized input and output, using the pointer to the top-left pixel and the pixel's distance between the real coordinates and the smallest following integer coordinates.

Input must be QASYMM8 and in single channel format.

Parameters
[in]pixel_ptrPointer to the top-left pixel value of a single channel input.
[in]strideStride to access the bottom-left and bottom-right pixel values
[in]dxPixel's distance between the X real coordinate and the smallest X following integer
[in]dyPixel's distance between the Y real coordinate and the smallest Y following integer
[in]iq_infoInput QuantizationInfo
[in]oq_infoOutput QuantizationInfo
Note
dx and dy must be in the range [0, 1.0]
Returns
The bilinear interpolated pixel value

Definition at line 53 of file ScaleHelpers.h.

References ARM_COMPUTE_ERROR_ON, arm_compute::dequantize_qasymm8(), and arm_compute::quantize_qasymm8().

55 {
56  ARM_COMPUTE_ERROR_ON(pixel_ptr == nullptr);
57 
58  const float dx1 = 1.0f - dx;
59  const float dy1 = 1.0f - dy;
60 
61  const float a00 = dequantize_qasymm8(*pixel_ptr, iq_info);
62  const float a01 = dequantize_qasymm8(*(pixel_ptr + 1), iq_info);
63  const float a10 = dequantize_qasymm8(*(pixel_ptr + stride), iq_info);
64  const float a11 = dequantize_qasymm8(*(pixel_ptr + stride + 1), iq_info);
65 
66  const float w1 = dx1 * dy1;
67  const float w2 = dx * dy1;
68  const float w3 = dx1 * dy;
69  const float w4 = dx * dy;
70  float res = a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
71  return static_cast<uint8_t>(quantize_qasymm8(res, oq_info));
72 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
float dequantize_qasymm8(uchar input, float offset, float scale)
Dequantize a scalar value from 8-bit asymmetric to floating-point.
Definition: helpers_asymm.h:62
uchar quantize_qasymm8(float input, float offset, float scale)
Quantize a floating-point scalar value to 8-bit asymmetric.
Definition: helpers_asymm.h:47

◆ delta_bilinear_c1_quantized() [2/2]

int8_t arm_compute::scale_helpers::delta_bilinear_c1_quantized ( const int8_t *  pixel_ptr,
size_t  stride,
float  dx,
float  dy,
UniformQuantizationInfo  iq_info,
UniformQuantizationInfo  oq_info 
)
inline

Computes bilinear interpolation for quantized input and output, using the pointer to the top-left pixel and the pixel's distance between the real coordinates and the smallest following integer coordinates.

Input must be QASYMM8_SIGNED and in single channel format.

Parameters
[in]pixel_ptrPointer to the top-left pixel value of a single channel input.
[in]strideStride to access the bottom-left and bottom-right pixel values
[in]dxPixel's distance between the X real coordinate and the smallest X following integer
[in]dyPixel's distance between the Y real coordinate and the smallest Y following integer
[in]iq_infoInput QuantizationInfo
[in]oq_infoOutput QuantizationInfo
Note
dx and dy must be in the range [0, 1.0]
Returns
The bilinear interpolated pixel value

Definition at line 88 of file ScaleHelpers.h.

References ARM_COMPUTE_ERROR_ON, arm_compute::dequantize_qasymm8_signed(), and arm_compute::quantize_qasymm8_signed().

90 {
91  ARM_COMPUTE_ERROR_ON(pixel_ptr == nullptr);
92 
93  const float dx1 = 1.0f - dx;
94  const float dy1 = 1.0f - dy;
95 
96  const float a00 = dequantize_qasymm8_signed(*pixel_ptr, iq_info);
97  const float a01 = dequantize_qasymm8_signed(*(pixel_ptr + 1), iq_info);
98  const float a10 = dequantize_qasymm8_signed(*(pixel_ptr + stride), iq_info);
99  const float a11 = dequantize_qasymm8_signed(*(pixel_ptr + stride + 1), iq_info);
100 
101  const float w1 = dx1 * dy1;
102  const float w2 = dx * dy1;
103  const float w3 = dx1 * dy;
104  const float w4 = dx * dy;
105  float res = a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
106  return static_cast<int8_t>(quantize_qasymm8_signed(res, oq_info));
107 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
int8_t quantize_qasymm8_signed(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a signed 8-bit asymmetric quantization scheme.
float dequantize_qasymm8_signed(char input, float offset, float scale)
Dequantize a scalar value from signed 8-bit asymmetric to floating-point.
Definition: helpers_asymm.h:75

◆ pixel_area_c1u8_clamp()

uint8_t arm_compute::scale_helpers::pixel_area_c1u8_clamp ( const uint8_t *  first_pixel_ptr,
size_t  stride,
size_t  width,
size_t  height,
float  wr,
float  hr,
int  x,
int  y 
)
inline

Return the pixel at (x,y) using area interpolation by clamping when out of borders.

The image must be single channel U8

Note
The interpolation area depends on the width and height ration of the input and output images
Currently average of the contributing pixels is calculated
Parameters
[in]first_pixel_ptrPointer to the first pixel of a single channel U8 image.
[in]strideStride in bytes of the image
[in]widthWidth of the image
[in]heightHeight of the image
[in]wrWidth ratio among the input image width and output image width.
[in]hrHeight ratio among the input image height and output image height.
[in]xX position of the wanted pixel
[in]yY position of the wanted pixel
Returns
The pixel at (x, y) using area interpolation.

Definition at line 126 of file ScaleHelpers.h.

References arm_compute::test::validation::reference::accumulate(), and ARM_COMPUTE_ERROR_ON.

Referenced by CpuScaleKernel::configure().

128 {
129  ARM_COMPUTE_ERROR_ON(first_pixel_ptr == nullptr);
130 
131  // Calculate sampling position
132  float in_x = (x + 0.5f) * wr - 0.5f;
133  float in_y = (y + 0.5f) * hr - 0.5f;
134 
135  // Get bounding box offsets
136  int x_from = std::floor(x * wr - 0.5f - in_x);
137  int y_from = std::floor(y * hr - 0.5f - in_y);
138  int x_to = std::ceil((x + 1) * wr - 0.5f - in_x);
139  int y_to = std::ceil((y + 1) * hr - 0.5f - in_y);
140 
141  // Clamp position to borders
142  in_x = std::max(-1.f, std::min(in_x, static_cast<float>(width)));
143  in_y = std::max(-1.f, std::min(in_y, static_cast<float>(height)));
144 
145  // Clamp bounding box offsets to borders
146  x_from = ((in_x + x_from) < -1) ? -1 : x_from;
147  y_from = ((in_y + y_from) < -1) ? -1 : y_from;
148  x_to = ((in_x + x_to) > width) ? (width - in_x) : x_to;
149  y_to = ((in_y + y_to) > height) ? (height - in_y) : y_to;
150 
151  // Get pixel index
152  const int xi = std::floor(in_x);
153  const int yi = std::floor(in_y);
154 
155  // Bounding box elements in each dimension
156  const int x_elements = (x_to - x_from + 1);
157  const int y_elements = (y_to - y_from + 1);
158  ARM_COMPUTE_ERROR_ON(x_elements == 0 || y_elements == 0);
159 
160  // Sum pixels in area
161  int sum = 0;
162  for(int j = yi + y_from, je = yi + y_to; j <= je; ++j)
163  {
164  const uint8_t *ptr = first_pixel_ptr + j * stride + xi + x_from;
165  sum = std::accumulate(ptr, ptr + x_elements, sum);
166  }
167 
168  // Return average
169  return sum / (x_elements * y_elements);
170 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
Definition: Accumulate.cpp:38