47 const float M00 = matrix[0];
48 const float M10 = matrix[1];
49 const float M20 = matrix[2];
50 const float M01 = matrix[0 + 1 * 3];
51 const float M11 = matrix[1 + 1 * 3];
52 const float M21 = matrix[2 + 1 * 3];
53 const float M02 = matrix[0 + 2 * 3];
54 const float M12 = matrix[1 + 2 * 3];
55 const float M22 = matrix[2 + 2 * 3];
57 const int width = src.
shape().x();
58 const int height = src.
shape().y();
61 for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx)
63 valid_mask[element_idx] = 1;
65 const int idx =
id.
x();
66 const int idy =
id.y();
67 const float z0 = M20 * idx + M21 * idy + M22;
69 const float x0 = (M00 * idx + M01 * idy + M02);
70 const float y0 = (M10 * idx + M11 * idy + M12);
72 const float xn = x0 / z0;
73 const float yn = y0 / z0;
74 id.set(0, static_cast<int>(std::floor(xn)));
75 id.set(1, static_cast<int>(std::floor(yn)));
76 if((0 <= yn) && (yn < height) && (0 <= xn) && (xn < width))
96 valid_mask[element_idx] = 0;
105 dst[element_idx] = constant_border_value;
109 id.set(0, std::max(0, std::min(static_cast<int>(xn), width - 1)));
110 id.set(1, std::max(0, std::min(static_cast<int>(yn), height - 1)));
115 dst[element_idx] =
bilinear_policy(src,
id, xn, yn, border_mode, constant_border_value);
129 uint8_t constant_border_value);
BorderMode
Methods available to handle borders.
InterpolationPolicy
Interpolation method.
T tensor_elem_at(const SimpleTensor< T > &src, Coordinates coord, BorderMode border_mode, T constant_border_value)
SimpleTensor< T > warp_perspective(const SimpleTensor< T > &src, SimpleTensor< T > &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
DataType data_type() const override
Data type of the tensor.
Output values are defined by bilinear interpolation between the pixels.
TensorShape shape() const override
Shape of the tensor.
Output values are defined to match the source pixel whose center is nearest to the sample position...
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
T x() const
Alias to access the size of the first dimension.
T bilinear_policy(const SimpleTensor< T > &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value)
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
Simple tensor object that stores elements in a consecutive chunk of memory.
Borders are left undefined.
Pixels outside the image are assumed to have the same value as the closest image pixel.
int num_elements() const override
Number of elements of the tensor.
bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode)