[R] recovering value of scalar from false color map and image

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sat Oct 18 19:33:59 CEST 2008


2008/10/18 Jan Theodore Galkowski <bayesianlogic at acm.org>:
> I have a JPEG map of temperature data, coded using a given legend where
> blues are cooler and reds hotter.  Is there any preexisting R magic or
> package which might let me recover the value of the scalar quantity so
> represented given the RGB values at each point in the picture?
>
> After processing, I'd also like to push the results back through the
> translate to get an RGB JPEG again.
>

 For starters, try read.jpeg() in the rimage package. That'll get your
jpeg into R as an imagematrix, with red, green and blue components.

 For your problem, if I've understood it correctly, I'd try the following:

 1. Use an image editing program (GIMP is free and open source) to
produce two cropped images, one of just the map area, and one purely
of the colours in the legend. So you've cut out the axes and so on.
(Actually you can probably read them into R with read.jpeg and crop it
there with something like foo[230:600,120:800,] once you've worked out
where the bits are)

 2. Read both these in using read.jpeg.

 3. Now assuming the legend is just a horizontal or vertical colour
ramp with some values, work out the mapping from RGB to temperature.
If you're lucky it will just be linear (or at least monotonic) with R
or B value. Try plotting slices across the legend, and either fit a
polynomial or construct a lookup table. If it's monotonic then you
might only need the R value, otherwise you've got a two-way lookup
table...

 4. Apply the polynomial function (or it's inverse) or the lookup
table to the map jpeg colours

 5. Profit!!????[1].

 6. Remember that JPEG files are lossy compression, so the image may
not exactly represent the values of the original data. It's got noise.

Fun problem....

Barry

[1] South Park reference.



More information about the R-help mailing list