MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / scale_image

Function scale_image

tests/validation/reference/CropResize.cpp:38–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36namespace
37{
38SimpleTensor<float> scale_image(const SimpleTensor<float> &in,
39 const TensorShape &out_shape,
40 InterpolationPolicy policy,
41 float extrapolation_value)
42{
43 ARM_COMPUTE_ERROR_ON(in.data_layout() != DataLayout::NHWC);
44
45 SimpleTensor<float> out{out_shape, DataType::F32, 1, QuantizationInfo(), DataLayout::NHWC};
46 // Compute the ratio between source width/height and destination width/height
47 const auto wr = static_cast<float>(in.shape()[1]) / static_cast<float>(out_shape[1]);
48 const auto hr = static_cast<float>(in.shape()[2]) / static_cast<float>(out_shape[2]);
49
50 const auto width = static_cast<int>(in.shape().y());
51 const auto height = static_cast<int>(in.shape().z());
52
53 Window win;
54 win.use_tensor_dimensions(out_shape);
55 execute_window_loop(
56 win,
57 [&](const Coordinates &out_id)
58 {
59 Coordinates in_id(out_id);
60 int idw = in_id.y();
61 int idh = in_id.z();
62
63 switch (policy)
64 {
65 case InterpolationPolicy::NEAREST_NEIGHBOR:
66 {
67 //Calculate the source coords without -0.5f is equivalent to round the x_scr/y_src coords
68 float x_src = std::floor(idw * wr);
69 float y_src = std::floor(idh * hr);
70 in_id.set(1, x_src);
71 in_id.set(2, y_src);
72
73 // If coordinates in range of tensor's width or height
74 if (is_valid_pixel_index(x_src, y_src, width, height, 0))
75 {
76 *reinterpret_cast<float *>(out(out_id)) =
77 tensor_elem_at(in, in_id, BorderMode::CONSTANT, extrapolation_value);
78 }
79 else
80 {
81 *reinterpret_cast<float *>(out(out_id)) = extrapolation_value;
82 }
83 break;
84 }
85 case InterpolationPolicy::BILINEAR:
86 {
87 float x_src = idw * wr;
88 float y_src = idh * hr;
89 in_id.set(1, std::floor(x_src));
90 in_id.set(2, std::floor(y_src));
91 if (is_valid_pixel_index(x_src, y_src, width, height, 0))
92 {
93 const int id_w = in_id[1];
94 const int id_h = in_id[2];
95

Callers 1

crop_and_resizeFunction · 0.85

Calls 9

floorFunction · 0.85
is_valid_pixel_indexFunction · 0.85
tensor_elem_atFunction · 0.85
QuantizationInfoClass · 0.50
data_layoutMethod · 0.45
shapeMethod · 0.45
yMethod · 0.45
zMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected