# Contouring an Image with ListContourPlot

I'm trying to take an image that consists of several noisy ellipses and use ListContourPlot to generate a contour of the image. However, I'm just getting a single dense line. If I binarize the image I get the correct result, but I lose the detail needed for the contour to be good. However, if I use Posterization with a value of two, it also doesn't work. What is Binarize doing that Posterize isn't, and why does ListContourPlot work with one but not the other?

Sidenotes: I've looked at the image data and the background of the image even before Posterization is mostly true black.

Contours also work with DistanceTransform.

Code:

FN = DialogInput[{filename = temp},
InputField[Dynamic[filename], String,
FieldHint -> "Enter your file name"],
FileNameSetter[Dynamic[filename], "Open",
Method -> "Preemptive"],
DefaultButton[DialogReturn[filename]]}]];
img = Import[FN];
img = ColorConvert[img, "Grayscale"];
(*img = ChanVeseBinarize[img]*)
img = ImageEffect[img, {"Posterization", 2}]
pic2 = ListContourPlot[ImageData[img, DataReversed -> True],
ContourShading -> None, Frame -> False, ContourStyle -> Yellow];

Show[img, pic2]


Image In:

Image Output:

• Your image has an alpha channel that you should remove. – chuy Nov 27 '17 at 18:44
• You can do this first: ColorConvert[RemoveAlphaChannel@img, "Grayscale"]. – chuy Nov 27 '17 at 18:49

With chuys hint:

img = Import["https://i.stack.imgur.com/vkvMu.png"]

imggray = ColorConvert[RemoveAlphaChannel@img, "Grayscale"]

colTable = {Black, Blue, Green, Yellow, Red};

contour = ListContourPlot[ImageData[imggray, DataReversed -> True],
ColorFunction -> (Blend[colTable, #] &), AspectRatio -> Automatic,
ImageSize -> Medium]


• This worked! Also, I can use posterization to change the density of the contours. – Adrian Smith Dec 4 '17 at 18:09