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

Function crop_image

tests/validation/reference/CropResize.cpp:132–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130
131template <typename T>
132SimpleTensor<float> crop_image(
133 const SimpleTensor<T> &src, Coordinates start, Coordinates end, int32_t batch_index, float extrapolation_value)
134{
135 TensorShape out_shape(src.shape()[0], static_cast<uint32_t>(abs(end[0] - start[0])) + 1,
136 static_cast<uint32_t>(abs(end[1] - start[1])) + 1);
137
138 SimpleTensor<float> out{out_shape, DataType::F32, 1, QuantizationInfo(), DataLayout::NHWC};
139
140 Window win;
141 win.use_tensor_dimensions(out_shape);
142 execute_window_loop(win,
143 [&](const Coordinates &id)
144 {
145 bool out_of_bounds = false;
146 Coordinates offset(id[0], 0, 0, batch_index);
147 for (uint32_t i = 1; i < 3; ++i)
148 {
149 offset.set(i, end[i - 1] < start[i - 1] ? start[i - 1] - id[i] : start[i - 1] + id[i]);
150 if (offset[i] < 0 || static_cast<uint32_t>(offset[i]) > src.shape()[i] - 1)
151 {
152 out_of_bounds = true;
153 break;
154 }
155 }
156 if (!out_of_bounds)
157 {
158 *reinterpret_cast<float *>(out(id)) =
159 static_cast<float>(*reinterpret_cast<const T *>(src(offset)));
160 }
161 else
162 {
163 *reinterpret_cast<float *>(out(id)) = extrapolation_value;
164 }
165 });
166 return out;
167}
168
169} // namespace
170

Callers 1

crop_and_resizeFunction · 0.85

Calls 4

absFunction · 0.85
QuantizationInfoClass · 0.50
shapeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected