What does the distance transform encode and how to calculate distance transfrom in the picture below?

My though is that there is a 2 in position (5,7) and the rest is 1 inside the black boundary. Outside would be 0.

enter image description here


The output of the distance transform depends on the applied vector norm (euclidean, maximum, manhattan, ...), see e.g. here or here.

From your example solution, I assume you take the Manhattan distance. Then, your result for the interior of the shape is correct. However, for the exterior of the region, why would it be zero? For the distance transform, the shape of the image does not count, it is only a pixel-based algorithm, where each pixel gets the value that matches its distance to the next non-zero pixel. Apply this to the outer pixels and you have the correct result.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.