I believe the problem is
distance with constraints... that is limitin gthe distance to paths that can be taken between points.
In the case of between cities, cars are generally limited to roads, unless you have a helecopter, in which case you are limited to the surface of the planet.
The problem is finding the distance between points within the bounds of some object or shape. That is 'constrained distances'.
As it happens I have been thinking of this problem, and a iterative distance function, with a write mask (constraint) may be able to help solve it.
Start with a all white image with a single black pixel at the start point of the distance function. Now mask it with a
write mask and finally run the distance function.
Code: Select all
convert distance_start.png -mask distance_bounds.png \
-morphology Distance Chebyshev \
+mask -fill black -opaque white -auto-level \
distance_result.png
The mask prevents the distance function from writing distance changes to the area outside the path, while a value of white in the source image ensures it does not contribute to the results (only values influenced by the single black starting pixel).
The last part turns off the mask, and makes anything still white black, before 'normalizing' the gradient to make it more visible.
Well it almost works...
It stops because IM is actually not applying the distance function iterativally, but only as a special two pass distance function. One pass forwards (top down) through the pixels in the image and one upward, both re-using the previous results immediately they are discovered. As such in this case the 'upward' pass gets the results most of the way.
Hmm running the distance function multiple times may work
Code: Select all
convert distance_start.png -mask distance_bounds.png \
-morphology Distance Chebyshev \
-morphology Distance Chebyshev \
+mask -fill black -opaque white -auto-level \
distance_result_2.png
Yes, complete coverage. Running the distance function a few times and it can go around corners, and get 'constrainted' results. (do not normalize if you actually want to make distance measurements)
The problem is I have disabled "iterative" count option for this special distance function, as it normally did not need it.
Looks like I'll have to re-enable the iterative count for distance again
Warning using a large Euclidean kernel is NOT recommended as it could 'jump over' a gap in the constraint mask, You will need to stick with smaller 1 pixel radius distance kernels, Chebyshev, Manhattan, Euclidean (knight). If the gap is more than one pixel you can also use octogonal distance function (integer knight -like)