16Ensemble::W2c(
const C&
clusters,
const C& centers,
const T& f,
const M& fmask,
path_mode mode)
18 using value_type =
typename T::value_type;
19 using mask_type =
typename M::value_type;
20 using cluster_type =
typename C::value_type;
22 static_assert(std::is_integral<cluster_type>::value,
"Integral clusters required.");
23 static_assert(std::is_integral<mask_type>::value,
"Integral mask required.");
28 GOOSEEYE_ASSERT(f.dimension() == m_shape_orig.size(), std::out_of_range);
29 GOOSEEYE_ASSERT(xt::all(xt::equal(fmask, 0) || xt::equal(fmask, 1)), std::out_of_range);
30 GOOSEEYE_ASSERT(m_stat == Type::W2c || m_stat == Type::Unset, std::out_of_range);
36 xt::pad_mode pad_mode = xt::pad_mode::constant;
40 pad_mode = xt::pad_mode::periodic;
48 xt::pad(xt::atleast_3d(
clusters), m_pad, pad_mode);
56 auto ix = m_shape[0] > 1 ? xt::range(1, m_shape[0] - 1) : xt::range(0, m_shape[0]);
57 auto iy = m_shape[1] > 1 ? xt::range(1, m_shape[1] - 1) : xt::range(0, m_shape[1]);
58 auto iz = m_shape[2] > 1 ? xt::range(1, m_shape[2] - 1) : xt::range(0, m_shape[2]);
60 xt::view(r, ix, iy, iz) = 0;
64 for (
size_t i = 0; i < MAX_DIM; ++i) {
65 xt::view(stamp, xt::all(), xt::keep(i)) -= m_pad[i][0];
70 for (
size_t istamp = 0; istamp < stamp.shape(0); ++istamp) {
74 GooseEYE::path({0, 0, 0}, {stamp(istamp, 0), stamp(istamp, 1), stamp(istamp, 2)}, mode);
76 for (
size_t h = m_pad[0][0]; h < F.shape(0) - m_pad[0][1]; ++h) {
77 for (
size_t i = m_pad[1][0]; i < F.shape(1) - m_pad[1][1]; ++i) {
78 for (
size_t j = m_pad[2][0]; j < F.shape(2) - m_pad[2][1]; ++j) {
80 auto label = Centers(h, i, j);
84 if (!label || Clusters(h, i, j) != label) {
88 for (
size_t p = 0; p <
path.shape(0); ++p) {
95 if (Clusters(h + dh, i + di, j + dj) != label && q < 0) {
101 if (!Fmask(h + dh, i + di, j + dj)) {
103 m_pad[0][0] +
path(q, 0),
104 m_pad[1][0] +
path(q, 1),
105 m_pad[1][0] +
path(q, 2)) += 1;
108 m_pad[0][0] +
path(q, 0),
109 m_pad[1][0] +
path(q, 1),
110 m_pad[1][0] +
path(q, 2)) += Fd(h + dh, i + di, j + dj);
array_type::tensor< int, 2 > path(const array_type::tensor< int, 1 > &x0, const array_type::tensor< int, 1 > &x1, path_mode mode=path_mode::Bresenham)
Compute a path between two pixels.