# How to superimpose contour lines on transformed image

My goal is to

superimpose contours lines or contour plots on distance transformed image.

• DistanceTransform[] has a few glitches, but it basically does what you want. What else do you want? Feb 19, 2014 at 16:38
• Just use an appropriate colorfunction for the distance transform... no need for ListContourPlot, I think.
– rm -rf
Feb 19, 2014 at 16:39
• @belisarius is anyway I can extract contour from listcontour plot. Feb 19, 2014 at 17:19
• There are lot.For example mathematica.stackexchange.com/a/31870/193 Feb 19, 2014 at 17:22
• @blisarius thanks Feb 19, 2014 at 17:26

If you use a DistanceFunction where a complete contour always falls on the pixels, like ManhattenDistance you can directly work on the image. The approach is pretty simple, calculate the distance transform

horse = Import["https://i.stack.imgur.com/KCfWy.png"];
dist = DistanceTransform[horse, DistanceFunction -> ManhattanDistance];

And then you set all distances to 1 which have a certain remainder. So if I want to have the contours for distances 1,5,9,... you use

lines = Map[Boole[Mod[#, 4] == 1] &, Round@ImageData[dist], {2} ] // Image

Superimposing is then as easy as laying the images over another, or using different color channels: