Height map color to grayscale

Does anyone know a tool or algorithm to transform a color height map into gray scaled one.

Color from Dark Blue (deepest oceans) to dark red-brown-ish (highest mountains).

If I just monochrome the image I get dark color for the deepest and the highest regions which is obviously wrong.

Any ideas are welcome.

Subsequent question:
Does anyone know what RhinoCommon methods are used in the “Hightfield from image” command?

Thanks in advance.

PS: I posted in this category because it’s more a CG question.

pipe your color image through a color ramp / gradient with the stops set as you need. Dark blue being black, red-brownish being white, stops inbetween as you need.

Thanks for the reply @nathanletwory

Is this a software, a type of software?
Any recommendations?

I tried a couple of modules for CPython3 to get the number of colors and the actual colors, but if the image is not of a very good quality the number of colors becomes too high and the output is ‘None’

There are equations for greyscale and there isn’t one right way to do it. There is typically 4 common schemes. I have a Grayscale Color component in Pufferfish with them but since I assume you want some code, check out the section of this page called “Luma Coding in Video Systems” for the different common weighted average schemes: https://en.m.wikipedia.org/wiki/Grayscale

1 Like

Grayscale isn’t what is really needed. One needs to map the different colors to the different height values. Color ramp / multistop gradient can help you interpolate.


Yes, exactly.

The problem is the number of colors. It is not based on luminescence or luminosity do not know the correct term here :blush:.

I tried even to reduce the colors by playing around with gimp, but still when I tried to scan it with Python the number of colors is huge.

Can you also attach the original image?

I tried, but it’s 40 mb

Do you mean original colors or original full-sized image with reduced colors?

Here are all my attempts:
map.7z (16.2 MB)

the file tst2inv.png I got closer to what I want, but all rivers become mountains :smiley:

Just original colors, not necessary the size. But I’ll get your zip and show something what I mean. You can take it from there (:

Hi Ivelin; As colors could be transformed to point in a cube with {-1,-1,-1,} and {1,1,1} extremities, you could first draw a curve representing the gradiant and then at each parameter of the curve affect a greyscale. If not precise you could use GraphMapper.
See there

1 Like

Thanks @laurent_delrieu,

I did not think of using gradient component.

I simply used the image sampler.
I’ll try to combine somehow both.

I’m puzzled.

How does a simple mesh component contain colors?

I have no experience of mesh and I don’t know its properties, but having color in it, how? :thinking:

A mesh can have color at Vertex in Rhinoceros/Grasshopper.
For your image you can use that

Then look at the points. The hard work is here and for this case it is not so simple …

1 Like

Maybe it would be easier to find another file with the height information directly encoded rather than trying to back calculate it?

1 Like

while this looks like an interesting problem, why not just use other sources?
your map seems to be simple elevation data… here is a nice 16 bit grayscale tiff source:

and if you need better data get an account (free) for: https://earthexplorer.usgs.gov/
there you can download all kinds of high res raw satellite data

even if you would manage to convert your color map, the loss of precision will be so great, not sure it is worth it

1 Like

Hi @atair,

The reason I want to do this is because all already grayscaled images about elevations I found contain only data for the land, not the underwater topography.

The sea is always the same level. And if you try to create a 3d model it doesn’t look ok.

Hi Graham,
How would this file look like? Is there specific format that contains this kind of data?

here is a full map with ocean floor:
be sure to run some image filters like auto-level on it before using it - image samplers in grasshopper / rhino only work on 8bit precision

here is how it looks like (edited crop):

1 Like

That image is viewed from an angle.

I am saying this because some satelite images contain shadows. That is impacting the result

its not. it is Plate Carree aka Geographic or LatLong
with a bit of math (wikipedia!) you can make it any projection you want
regarding the shadows - also no.

1 Like

Ivelin, I encouter the same ptoblem as you. I ended using a, image similar to the one from Atair.
For projecting on an earth with unit in kilometer I do that. In order to have good longitude, a rotation of 180° is necessary. The 0 of longitude is on the middle.

For the elevation I managed to do that. Not super precise, but the mesh was heavy