[GRASS-user] Invert values of raster image

Dear list.

I have a raster file with values coded in 8 bit grey scale 0-255. I would like to invert the raster values so that 255 is now 0 and 0 is now 255. I have not found an out of the box solution in grass but have tried the r.reclass function. I generated a reclass rule file but am not sure about the form of the file. In the grass help file the examples given show reclassification for only 5 or 6 classes. I essentially need to reclass 255 values.

Below is the format of my reclass file.

Many thanks for your help

Wesley

1 255
2 254
3 253
.
.
.
.
.
.
.
.
253 3
254 2
255 1

Wesley Roberts MSc.
Researcher: Earth Observation (Ecosystems)
Natural Resources and the Environment
CSIR
Tel: +27 (21) 888-2490
Fax: +27 (21) 888-2693

"To know the road ahead, ask those coming back."
- Chinese proverb

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.

On 23/02/09 11:16, Wesley Roberts wrote:

Dear list.

I have a raster file with values coded in 8 bit grey scale 0-255. I
would like to invert the raster values so that 255 is now 0 and 0 is
now 255. I have not found an out of the box solution in grass but
have tried the r.reclass function.

How about r.recode with a rule such as:

old_low:old_high:new_low:new_high
0:255:255:0

?

I generated a reclass rule file
but am not sure about the form of the file.

You need a '=', so

0=255
1=254
etc

Moritz

Wesley wrote:

I have a raster file with values coded in 8 bit grey scale
0-255. I would like to invert the raster values so that 255
is now 0 and 0 is now 255.

If you are only interested in flipping the colors, and not actually the
data, you might try the r.colors -n flag.

e.g
  r.colors yourmap -n color=grey255

or to really flip values, instead of r.reclass you might try r.mapcalc:
  r.mapcalc "flippedmap = 255 - yourmap"

Hamish