# 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. Dec 11, 2018 at 17:25

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]


• 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... Dec 11, 2018 at 18:06
• @TeM Did it work out? Dec 17, 2018 at 14:24
• Glad to hear that! You're welcome! Dec 21, 2018 at 10:23