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

Function erode

tests/validation/reference/Erode.cpp:41–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39{
40template <typename T>
41SimpleTensor<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
81template SimpleTensor<uint8_t>
82erode(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value);

Callers

nothing calls this directly

Calls 10

index2coordFunction · 0.85
tensor_elem_atFunction · 0.85
shapeMethod · 0.45
data_typeMethod · 0.45
num_elementsMethod · 0.45
xMethod · 0.45
yMethod · 0.45
setMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected