# Numeric data from a color map

Importing the following image (without a scale):

and knowing the extreme temperatures, is it possible to obtain the graduated scale?

Also, it would be interesting to get the temperatures of all the points by moving the cursor over the image.

Thanks a lot!

• Does the color bar really belong to the image? It would be very helpful to have the precise color gradient that was used for that image. – Henrik Schumacher Dec 11 '18 at 17:25
• @HenrikSchumacher: I arranged as requested. Thanks for the intervention. – TeM Dec 11 '18 at 17:34

If the color bar posted by OP really belongs to the image then the following should provide quite a good approximation. First, I extract the color bar scale and the actual image actualimage from the plot. By hand. This can certainly be automated somehow. Next, I use Nearest to build up a lookup table nf for color values. (This will result is strange results for pixels in the image that have a color that does not appear in the color bar. But this should not happen anyway.) Finally, I apply the NearestFunction nf to each pixel in order to find the temperature value whose color value on the color bar is closest to the pixel.

img = Import["https://i.stack.imgur.com/US42T.png"];
scale = Mean /@ ImageData[img][[27 ;; -26, -90 ;; -60]];
actualimage = ImageData[img][[;; , 1 ;; -112]];
nf = Nearest[scale -> Reverse@Subdivide[-7.2, 11.0, Length[scale] - 1]];
T = ArrayReshape[nf[Flatten[actualimage, 1], 1],Dimensions[actualimage][[1 ;; 2]]];


Here is a grayscale version of the resulting temperature array T:

Image[Rescale@T]


• First of all thank you! In reality, I only have images of some cameras, without the respective scale, but I only know the extreme temperatures of two points. – TeM Dec 11 '18 at 18:00
• Hm. That's too bad. We have to interpolate between these extreme values somehow. And it is not obvious how to do that because color space is three-dimensional and a color bar can be any continuous curve in this 3-space. I would guess that the cameras should have a documentation that tells you how this should be done. Maybe the cameras are also able to return grayscale images? Grayscales would be straightforward to interpolate... – Henrik Schumacher Dec 11 '18 at 18:06
• With my camera you can get images in 'gray scale' and 'rainbow'. – TeM Dec 11 '18 at 18:20
• @TeM Did it work out? – Henrik Schumacher Dec 17 '18 at 14:24
• Yes thanks!! =) – TeM Dec 21 '18 at 10:20