Search code examples
pythonrgbdata-conversion

How to build elevation scale from an RGB map?


I need to build a correspondence map between colors and altitudes. The elevation file has blue color for sea and green/yellow/brown colors for elevation. The advice says:

Find the pixel of the Mont Blanc (4810 m).

Text

I'm working with Python. I don't know how to solve this. I converted the map into a NumPy array of shape (2860,4490,3) with RGB values and want to transform into (2860,4490) with elevation value in meter.


Solution

  • Convert the RGB image to HSV colorspace to see with 'Hue' landmass can be linearly mapped. Treat water separately.

    • Read slide 13 here.
    • Last answer here illustrates this.
    • You could use scikit image for processing:
    from skimage.color import rgb2hsv
    
    rgb_img = np.array(your_image)
    hsv_img = rgb2hsv(rgb_img)
    hue_img = hsv_img[:, :, 0]
    

    Taken from here.