I am implementing a contour-finding algorithm for pixel-wide contours in binary images. It needs to be robust against deletion of individual pixels (i.e. pixel-wide gaps).
Various attempts at dilation & erosion kernels have not yielded a reliable solution.
Instead the reliable solution I want ot implement is to pass a pattern matching kernel over the image, which can directly fill in the gaps based on surrounding pixels. For example, when the exact pattern on the left is observed at a location, it is replaced with the right (where * means wildcard):
[1 * *] [1 * *]
[* 0 *] ==> [* 1 *]
[* * 1] [* * 1]
[1 0 *] [1 0 *]
[* 0 1] ==> [* 1 1]
[* * *] [* * *]
[* 1 *] [* 1 *]
[* 0 *] ==> [* 1 *]
[* 1 *] [* 1 *]
And define the ~14 or so replacements necessary to fill in the possible gaps in each 3x3 window.
It could be implemented in raw Python but likely to be extremely slow without low level vectorized operations.
Can this be done through OpenCV or some other fast operation?