| 130 | |
| 131 | template <typename T> |
| 132 | SimpleTensor<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 |
no test coverage detected