Skip to content

Instantly share code, notes, and snippets.

@matt-42
Created February 18, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-42/e94ced16527aeeace64d to your computer and use it in GitHub Desktop.
Save matt-42/e94ced16527aeeace64d to your computer and use it in GitHub Desktop.
fast erosion with vpp
template <typename I, typename O>
void erode(const I& img, O& out)
{
auto win = make_array(vint2{-4, 0}, vint2{-3, 0}, vint2{-2, 0}, vint2{-1, 0},
vint2{ 1, 0}, vint2{ 2, 0}, vint2{ 3, 0}, vint2{ 4, 0},
vint2{0, -7}, vint2{0, -6}, vint2{0, -5}, vint2{0, -4}, vint2{0, -3}, vint2{0, -2}, vint2{0, -1},
vint2{0, 1}, vint2{0, 2}, vint2{0, 3}, vint2{0, 4}, vint2{0, 5}, vint2{0, 6}, vint2{0, 7});
auto nbh = const_box_nbh2d<typename I::value_type, 9, 15>(img);
pixel_wise(nbh, out) | [win] (const auto& n, auto& o)
{
auto r = n(0,0);
for (int i = 0; i < win.size(); i++)
r = std::min(n(win[i]), r);
o = r;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment