Suppose that I have a mask of an object and a point. I want to find the closest point of the object mask to the point.
For example, in my drawing, there is an object, the blue shape in the image (assume inside is also the part of the object mask). And the red point is the point from which I want to find the closest distance to the object mask.
So, I want to find the thick green line as it is the shortest distance to the mask not the other ones (pink, orange, etc). I can do this using one of the following ways:
- An inefficient way is to find the distances of all the pixels to the point using something like this (brute-force).
- Another way is to create many lines towards the mask with epsilon angle difference and find the closest point over that line, which is also not very nice.
- I can create lines over the edge, and find the closest point of each of those lines on the object border. (This may not be as easy as I thought, first I need to find the outer border, etc.)
But none of these methods are is elegant. I am wondering what is a more elegant and the most efficient way to determine this?