What is the basis for creating a depth map for an existing image?

In other words, how does such a utility decide the distance from the camera of say groups of pixels and therefrom decide the level of each pixel in the map?

I do know what a depth map is and what the pixel levels therein are supposed to represent.

Thanks for looking.

P.S. I’m not talking about cell-phone images with data from a built-in depth-sensor.

I’d say to get a reliable depth map you need a special sensor of some kind (actual depth sensor, stereo camera, …). Without that, I don’t see how you would infer the depth information, as that information is simply not included in the pure RGB image.
Maybe nowadays some AI tools could give acceptable results, but I don’t know any.

IIIRC there have indeed been AI attempts to infer the depth map from bokeh basically (the blur of objects depends on distance/depth). There is more related stuff on “depth from defocus”, but seems to require more than one image captured at different focus points, or having “split” right/left phase detect pixels

Thanks but I am talking about the depth map options in e.g. GIMP/G’MIC or in the RawTherapee DeHaze function which has a ‘Depth Map’ check box and a ‘Depth’ slider.

Both work on ordinary single images although G’MIC does have some 3D stuff too.

some cameras capture the depth map while capturing the image and store them in the file as metadata.