[GRASSLIST:58] d.rgb question

I have used r.in.gdal to import a rgb tif (it is a scanned map). I'd
like to display it as it looks when I view it with gimp. r.in.gdal
imported the tif as test.1, test.2, and test.3 (I assume for the 3 color
bands). After reading though some man pages, it looks like d.rgb is what
I should use to superimpose all 3 bands (hopefully getting something
that looks "colorwise", like the original tif).

However, no matter which order I "superimpose" the color bands with
d.rgb, I can not get anything to look like the original. I am using the
wrong function here, or perhaps just applying it incorrectly?

Kirk
--
Kirk R. Wythers Department of Forest Resources
Tel: 612.625.2261 University of Minnesota
Fax: 612.625.521 1530 Cleveland Ave. N
Email: kwythers@umn.edu Saint Paul, MN 55108 USA

On Fri, 2003-05-16 at 15:21, John Preston wrote:

You need to set the colors to grey scale for the three maps test.1,
test.2 and test3.

ie. r.colors map=test.1 golor=gray
etc

then d.rgb will work.

That did it. Thanks

>
> Kirk

--
Kirk R. Wythers Department of Forest Resources
Tel: 612.625.2261 University of Minnesota
Fax: 612.625.521 1530 Cleveland Ave. N
Email: kwythers@umn.edu Saint Paul, MN 55108 USA

Kirk R. Wythers wrote:

> You need to set the colors to grey scale for the three maps test.1,
> test.2 and test3.
>
> ie. r.colors map=test.1 golor=gray
> etc

Actually, you should use color=rules, e.g.

  GRASS:~ > r.colors map=test.1 color=rules
  Enter rules, "end" when done, "help" if you need it.
  Data range is 0 to 255
  > 0 black
  > 255 white
  > end
  Color table for [test.1] set to rules

This will ensure that 0 is black and 255 is white.

Using color=gray will map the lowest existing category to black and
the highest existing category to white; if the map doesn't use the
entire 0-255 range, you will get the wrong result.

Also, you can read the rules from a file with e.g.

  r.colors map=test.1 color=rules < gray.rules

where gray.rules contains:

  0 black
  255 white
  end

--
Glynn Clements <glynn.clements@virgin.net>

Glynn Clements writes:
> Using color=gray will map the lowest existing category to black and
> the highest existing category to white; if the map doesn't use the
> entire 0-255 range, you will get the wrong result.

Why is this left up to users to set correctly? Why doesn't importing
an image do this automatically?

--
--My blog is at angry-economist.russnelson.com | "I have officially heard
Crynwr sells support for free software | PGPok | every excuse for being
521 Pleasant Valley Rd. | +1 315 268 1925 voice | assigned a single room at
Potsdam, NY 13676-3213 | +1 315 268 9201 FAX | FGC." --Liz Perch

Russell Nelson wrote:

> Using color=gray will map the lowest existing category to black and
> the highest existing category to white; if the map doesn't use the
> entire 0-255 range, you will get the wrong result.

Why is this left up to users to set correctly? Why doesn't importing
an image do this automatically?

Because r.in.gdal doesn't write a colour table unless the file itself
has a colour table (bear in mind that r.in.gdal isn't just for
images). Or, rather, it didn't in 5.0.2 and earlier; this has recently
been fixed in the CVS HEAD.

Also, GDAL itself goes a bit too far in its abstraction; the caller
just gets a grid of integers, with no way of knowing what the "white"
value should be. The CVS HEAD version guesses, and uses 0-255 for
8-bit unsigned data and 0-65535 for unsigned 16-bit data (i.e. if you
import 4-bit or 12-bit data, you will get a very dark image).

BTW, this was discussed in mid-March on the development list, in the
thread entitled "r.in.gdal updates?".

--
Glynn Clements <glynn.clements@virgin.net>

Glynn Clements writes:
> images). Or, rather, it didn't in 5.0.2 and earlier; this has recently
> been fixed in the CVS HEAD.

Good! You should set defaults so that most people don't need to
change them.

--
--My blog is at angry-economist.russnelson.com | "I have officially heard
Crynwr sells support for free software | PGPok | every excuse for being
521 Pleasant Valley Rd. | +1 315 268 1925 voice | assigned a single room at
Potsdam, NY 13676-3213 | +1 315 268 9201 FAX | FGC." --Liz Perch

On Fri, May 16, 2003 at 03:08:54PM -0500, Kirk R. Wythers wrote:

I have used r.in.gdal to import a rgb tif (it is a scanned map). I'd
like to display it as it looks when I view it with gimp. r.in.gdal
imported the tif as test.1, test.2, and test.3 (I assume for the 3 color
bands).

BTW: I have updated r.in.gdal to write in this case
test.blue, test.green, test.red
and to apply a grey scale color table.
The new version should come with 5.0.3 (or get the source code from CVS).

After reading though some man pages, it looks like d.rgb is what
I should use to superimpose all 3 bands (hopefully getting something
that looks "colorwise", like the original tif).

Yes.

However, no matter which order I "superimpose" the color bands with
d.rgb, I can not get anything to look like the original. I am using the
wrong function here, or perhaps just applying it incorrectly?

You have to assign a grey color table first:

r.colors test.1 col=grey
r.colors test.2 col=grey
r.colors test.3 col=grey
d.rgb ...

Hope this helps,

Markus Neteler

On Fri, May 16, 2003 at 11:03:21PM +0100, Glynn Clements wrote:

Kirk R. Wythers wrote:

> > You need to set the colors to grey scale for the three maps test.1,
> > test.2 and test3.
> >
> > ie. r.colors map=test.1 golor=gray
> > etc

Actually, you should use color=rules, e.g.

  GRASS:~ > r.colors map=test.1 color=rules
  Enter rules, "end" when done, "help" if you need it.
  Data range is 0 to 255
  > 0 black
  > 255 white
  > end
  Color table for [test.1] set to rules

This will ensure that 0 is black and 255 is white.

Using color=gray will map the lowest existing category to black and
the highest existing category to white; if the map doesn't use the
entire 0-255 range, you will get the wrong result.

Right - sorry for the r.colors mistake in my previous mail.
The updated r.in.gdal applies above suggested fixed color table.

Markus Neteler