| 39 | { |
| 40 | template <typename T> |
| 41 | SimpleTensor<T> erode(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) |
| 42 | { |
| 43 | /* |
| 44 | -1 x +1 |
| 45 | -1 [tl][tc][tr] -1 |
| 46 | y [ml][xy][mr] y |
| 47 | +1 [bl][bc][br] +1 |
| 48 | -1 x +1 |
| 49 | erode: |
| 50 | dst(x, y) = min[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = min({tl, tc, tr, ml, xy, mr, bl, bc, br}) |
| 51 | */ |
| 52 | SimpleTensor<T> dst(src.shape(), src.data_type()); |
| 53 | |
| 54 | const uint32_t num_elements = src.num_elements(); |
| 55 | #if defined(_OPENMP) |
| 56 | #pragma omp parallel for |
| 57 | #endif /* _OPENMP */ |
| 58 | for (uint32_t i = 0; i < num_elements; ++i) |
| 59 | { |
| 60 | Coordinates coord = index2coord(src.shape(), i); |
| 61 | const int x = coord.x(); |
| 62 | const int y = coord.y(); |
| 63 | |
| 64 | std::array<T, 9> neighbours = {{0}}; |
| 65 | for (int row = y - 1, j = 0; row <= y + 1; ++row) |
| 66 | { |
| 67 | for (int col = x - 1; col <= x + 1; ++col, ++j) |
| 68 | { |
| 69 | coord.set(0, col); |
| 70 | coord.set(1, row); |
| 71 | neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | dst[i] = *std::min_element(neighbours.cbegin(), neighbours.cend()); |
| 76 | } |
| 77 | |
| 78 | return dst; |
| 79 | } |
| 80 | |
| 81 | template SimpleTensor<uint8_t> |
| 82 | erode(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); |
nothing calls this directly
no test coverage detected