37 SimpleTensor<float> scale_image(
const SimpleTensor<float> &in,
const TensorShape &out_shape,
InterpolationPolicy policy,
float extrapolation_value)
43 const auto wr =
static_cast<float>(in.shape()[1]) / static_cast<float>(out_shape[1]);
44 const auto hr =
static_cast<float>(in.shape()[2]) / static_cast<float>(out_shape[2]);
46 const auto width =
static_cast<int>(in.shape().y());
47 const auto height =
static_cast<int>(in.shape().z());
50 win.use_tensor_dimensions(out_shape);
53 Coordinates in_id(out_id);
62 float x_src = std::floor(idw * wr);
63 float y_src = std::floor(idh * hr);
74 *
reinterpret_cast<float *
>(out(out_id)) = extrapolation_value;
80 float x_src = idw * wr;
81 float y_src = idh * hr;
82 in_id.set(1, std::floor(x_src));
83 in_id.set(2, std::floor(y_src));
86 const int id_w = in_id[1];
87 const int id_h = in_id[2];
89 const float dx = x_src - id_w;
90 const float dy = y_src - id_h;
91 const float dx_1 = 1.0f - dx;
92 const float dy_1 = 1.0f - dy;
97 in_id.set(1, id_w + 1);
101 in_id.set(2, id_h + 1);
103 in_id.set(1, id_w + 1);
104 in_id.set(2, id_h + 1);
107 *
reinterpret_cast<float *
>(out(out_id)) = tl * (dx_1 * dy_1) + tr * (dx * dy_1) + bl * (dx_1 * dy) + br * (dx * dy);
111 *
reinterpret_cast<float *
>(out(out_id)) = extrapolation_value;
123 template <
typename T>
124 SimpleTensor<float> crop_image(
const SimpleTensor<T> &
src, Coordinates
start, Coordinates
end, int32_t batch_index,
float extrapolation_value)
126 TensorShape out_shape(src.shape()[0],
static_cast<uint32_t
>(abs(end[0] - start[0])) + 1, static_cast<uint32_t>(abs(end[1] - start[1])) + 1);
128 SimpleTensor<float> out{ out_shape,
DataType::F32, 1, QuantizationInfo(), DataLayout::NHWC };
131 win.use_tensor_dimensions(out_shape);
134 bool out_of_bounds =
false;
135 Coordinates
offset(
id[0], 0, 0, batch_index);
136 for(uint32_t i = 1; i < 3; ++i)
138 offset.set(i, end[i - 1] < start[i - 1] ? start[i - 1] -
id[i] : start[i - 1] +
id[i]);
139 if(
offset[i] < 0 || static_cast<uint32_t>(
offset[i]) > src.shape()[i] - 1)
141 out_of_bounds =
true;
147 *
reinterpret_cast<float *
>(out(
id)) = static_cast<float>(*reinterpret_cast<const T *>(
src(
offset)));
151 *
reinterpret_cast<float *
>(out(
id)) = extrapolation_value;
159 template <
typename T>
171 for(uint32_t i = 0; i < boxes.
shape()[1]; ++i)
174 std::floor((*reinterpret_cast<const float *>(boxes(
Coordinates(0, i)))) * (src.
shape()[2] - 1) + 0.5f));
176 std::floor((*reinterpret_cast<const float *>(boxes(
Coordinates(2, i)))) * (src.
shape()[2] - 1) + 0.5f));
177 SimpleTensor<float> cropped = crop_image(src, start, end, box_ind[i], extrapolation_value);
178 SimpleTensor<float> scaled = scale_image(cropped, scaled_image_shape, method, extrapolation_value);
179 std::copy_n(reinterpret_cast<float *>(scaled.
data()), scaled.
num_elements(),
reinterpret_cast<float *
>(out(
Coordinates(0, 0, 0, i))));
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
InterpolationPolicy
Interpolation method.
T tensor_elem_at(const SimpleTensor< T > &src, Coordinates coord, BorderMode border_mode, T constant_border_value)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
1 channel, 1 F32 per channel
Output values are defined by bilinear interpolation between the pixels.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
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...
bool is_valid_pixel_index(int x, int y, int width, int height, int border_size)
Checks if a pixel has valid coordinates.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
SimpleTensor< float > crop_and_resize(const SimpleTensor< T > &src, const SimpleTensor< float > &boxes, SimpleTensor< int32_t > box_ind, Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value)
Quantization information.
DataLayout data_layout() const override
Data layout of the tensor.
void end(TokenStream &in, bool &valid)
Simple tensor object that stores elements in a consecutive chunk of memory.
Num samples, height, width, channels.
int num_elements() const override
Number of elements of the tensor.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
const T * data() const
Constant pointer to the underlying buffer.