Created
February 18, 2015 14:33
-
-
Save matt-42/e94ced16527aeeace64d to your computer and use it in GitHub Desktop.
fast erosion with vpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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