[GRASS-dev] any way to know color assigned to a cell?

Bob Covill bcovill at tekmap.ns.ca
Wed Apr 18 15:22:06 EDT 2007


Michael,

If you are looking to duplicate d.histogram why not use r.stats? This
will output raster values with the percent or area which could be used
for plotting a histogram. If this did work it could be modified to
output the associated raster color along with the other values. Maybe I
am missing the point?

On a related issues I have used a modified version of r.stats for a
while now to create equalized color bars for raster maps. You simply
calculate the distribution over a set number of color breaks, drop a
custom colortable over the breaks and apply with r.colors rules=.

Hope this helps.

--
Bob

On Wed, 2007-04-18 at 09:30 -0700, Michael Barton wrote:
> This is fine, but I'm afraid that it won't help planned implementation. This
> is partly because I didn't phrase my question correctly. What I really need
> to know is what color is assigned to a cat value. The idea is to do
> histogramming in wxPython. It might be nice to have the histogram show the
> map colors like d.histogram can. To do that, I need to know the color
> assigned to a cat. However, to get colors by querying every cell in a map
> with r.what would take a very long time.
> 
> Michael
> 
> 
> On 4/18/07 7:05 AM, "Bob Covill" <bcovill at tekmap.ns.ca> wrote:
> 
> > On Thu, 2007-04-19 at 01:51 +1200, Hamish wrote:
> >> Michael:
> >>>>> If have a map with values from 0-255 I create a set of color rules
> >>>>> such that
> >>>>> 0% = green
> >>>>> 100% = red
> >>>>> 
> >>>>> GRASS will create a color table that will assign a nice gradient of
> >>>>> colors from 0:255:0 to 255:0:0 to the values from 0-255.
> >>>>> 
> >>>>> Is there any way when querying a single cell of that map to know
> >>>>> what color has been assigned to it?
> >> Glynn:
> >>>> Set a 1x1 region around the cell, then r.out.ppm | pnmnoraw | sed.
> >>>> 
> >>>> Or r.mapcalc 'out = (r#map * 256 + g#map) * 256 + b#map', query the
> >>>> composite map and decode the category number.
> >>>> 
> >>>>> Similarly, is there any way to know what color has
> >>>>> been assigned to any value in the 0-255 range?
> >>>> 
> >>>> Set a 1x1 region, r.mapcalc "tmp = $value", r.out.ppm ...
> >>>> 
> >>>> Seriously; this is how d.rast.edit.tcl does it.
> >>>> 
> >>>> Yeah; we could probably do with a "r.what.colors" module.
> >> Michael:
> >>> I was contemplating a wxPython histograming module, like the TclTk
> >>> profiling module, and liked the option in d.histogram of being able to
> >>> use the color table for the histogram colors. But this seems like a
> >>> pretty intensive batch of calculations to do it.
> >> 
> >> 
> >> you could try "r.profile -c" with a profile which starts and stops at
> >> the cell center (length=0). Also it should be very simple to add a flag
> >> just like "r.profile -c" to r.what, if that helps.
> > 
> > I have a version of r.what that I modified to optionally output RGB
> > color. If interested I could commit to CVS?
> > 
> > --
> > Bob
> > 
> > 
> >> 
> >> But probably the most direct solution is a SWIG-Python interface to the
> >> libgis color-lookup fns themselves.
> >> 
> >> 
> >> Hamish
> >> 
> >> _______________________________________________
> >> grass-dev mailing list
> >> grass-dev at grass.itc.it
> >> http://grass.itc.it/mailman/listinfo/grass-dev
> > 
> > 
> 
> __________________________________________
> Michael Barton, Professor of Anthropology
> School of Human Evolution & Social Change
> Center for Social Dynamics & Complexity
> Arizona State University
> 
> phone: 480-965-6213
> fax: 480-965-7671
> www: http://www.public.asu.edu/~cmbarton
> 
> 




More information about the grass-dev mailing list