# Finding Contours in Photo to Create a Topographical Map

I am setting up a special table to simulate the scenario in this problem in this problem, but instead of finding the geodesics, I want to create a topographical map using the contours.

Here is a picture of a sheet with steel ball bearings on it:

I am using a gray sheet so that way contrast shows up the most (ideally it would be RGBColor[.5,.5,.5]).

I am not sure how to do this using Mathematica.

In essence, this is to create a 'hybrid' computer where the square trampoline, camera, and Mathematica program will be the parts of the digital-analog computer.

UPDATE: I tried it in a darker room, painted balls, ironed the sheet (impossible to do perfectly because of material), and used heavier balls. This allows us to see closed loops.

I took Vitaliy Kaurov's answer below and made it a simple function:

topographicalMap[url_, colorMode_] :=
Module[{image, resizedImage},
(* Import and convert the image to grayscale *)
image = ColorConvert[CloudImport[url], "Grayscale"];

(* Resize image for speed *)
resizedImage = ImageData[ImageResize[image, 50]];

(* Generate the topographical map based on colorMode *)
If[colorMode,
(* If colorMode is True, use a colored contour plot *)
Rasterize[ ListContourPlot[resizedImage, Contours -> 7, ColorFunction -> "Rainbow", Frame->False]],
(* Else, use a black and white contour plot *)
Rasterize[ ListContourPlot[resizedImage, Contours -> 7, ContourShading -> None,Frame->False]]
]
]


The whole purpose of this is to just demonstrate a concept for a hobby research project. It did not have to be perfect. I just wanted to share this better photo.

• Begin here in Help: example/DetectEdgesInImages, There are EdgeDetect, MorphologicalBinarize Commented Nov 14, 2023 at 21:39
• @RolandF I have used those two. But they find objects in images. I am not sure how to generalize that to make a topographical map. Commented Nov 14, 2023 at 22:02
• Do you think it is even possible? I mean from one image of a surface you can not determine elevation of any point. Topographical map of moon is not calculated from one image. The elevation is calculated by the time it takes for a signal to return to a satellite. Images serve only to pair points with their elevation to make a topographical map. Commented Nov 14, 2023 at 22:36
• How do you use the color of the moon or the color of the green meadow to determine the elevation? You have to make the job for you simple as possible. I would take an elastic sheet of one color and draw orthogonal grid on it in different color. Say, white sheet and black grid. Then make a photo with balls on it from predefined distance with lightings from many different points so that there is no shadow and then by deformation of the lines of grid you could compute the elevation. Commented Nov 14, 2023 at 22:49
• If you light the subject from many different angles, you can estimate the normal map, though the depth is another matter. Commented Nov 15, 2023 at 12:38

For this you got only the data that image gives you. That's why you must have a good no-shadow no-tint defect-free lightning and surfaces. Then potentially you can do something like this. I will Import your image:

i=ColorConvert[Import["https://i.sstatic.net/6feHG.jpg"],"Grayscale"];


Resize it for faster tests:

iR=ImageData[ImageResize[i,100]];


Then try getting contours from the ImageData (you can see damaging effects of shadows and other defects - they do not allow closed loops arround the balls):

ListContourPlot[iR,Contours->7,ColorFunction->"Rainbow"]


You can also try going contour-only:

ListContourPlot[iR, Contours -> 7, ContourShading -> None]