Finding the Distance from A Pixel to an Edge
I am trying to write an algorithm to find the minimum distance from every
pixel in the image to an edge which is black. An example image is found
below:
This is the algorithm currently have:
Starting from the pixel (R,C) I check every pixel around (R,C) that is d=1
pixels away from R,C. If I do not hit a black pixel, then I check every
pixel around (R,C) that is d =2 pixels away from R,C ... and this carries
on (with d increasing) until I find a black pixel and then I calculate the
Euclidean Distance from R,C. Note that I am making sure that the pixels I
check do not exceed the boundaries of the image).
However because I am doing this for every pixel, the algorithm is very slow.
Does anyone know a faster way to doing this? Any help will be highly
appreciated. I am coding in C++ and OpenCV so any algorithm making use of
these will be preferred.
No comments:
Post a Comment