[GRASS-user] How to rescale

I created a raster using *r.grow.distance*
I need to rescale that file to a scale 0-255 but in reverse order where high
values in distance file will be converted in low values to the rescaled
file.
I'm using the following command:
*
*
But the output file has a range 60-255
What's going wrong?
Is there any better way to do that?

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-rescale-tp7169303p7169303.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On Mon, Jan 9, 2012 at 8:42 PM, leonidas <leonidas_liakos@yahoo.gr> wrote:

I created a raster using *r.grow.distance*
I need to rescale that file to a scale 0-255 but in reverse order where high
values in distance file will be converted in low values to the rescaled
file.
I'm using the following command:
*
*
But the output file has a range 60-255
What's going wrong?
Is there any better way to do that?

Try

eval `r.univar -g map=myrast`
r.mapcalc "myrast.invscaled = round((1.0 - myrast / $max) * 255.0)"

Original 0 will be 255, original maximum value will be 0, using
round() in order to get an integer map with rounded values which can
be exported as type Byte.

HTH,

Markus M

On 09/01/12 20:42, leonidas wrote:

I created a raster using *r.grow.distance*
I need to rescale that file to a scale 0-255 but in reverse order where high
values in distance file will be converted in low values to the rescaled
file.
I'm using the following command:

>r.recode input=dist_file output=recoded_file <<EOF
>0:133000:255:0
>EOF

[BTW: I don't know how you formatted your mail, but for me the above three lines showed as:

*

But the output file has a range 60-255
What's going wrong?
Is there any better way to do that?

Are you sure that 133000 is the max of your map in the region you are using ? Be aware that r.info gives the info for the whole map, ignoring region settings and a possible mask. You can use r.univar or r.stats to see the max in the current region/mask.

Moritz

Indeed, I run *r.univar* and the max value is 101812!!!
So using:
r.recode input=dist_coastline output=recoded_file
0:101812:255:0

the range of the output file was 0-255

I also checked Markus method.
eval `r.univar -g map=myrast` returns max value = 101812.211145335

I re-run r.recode using 101812.211145335 as max value.

Running r.univar for the two output files I get defferent results (but very
simiral):

Output from Markus method:

Output from Moritz method:

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-rescale-tp7169303p7177559.html
Sent from the Grass - Users mailing list archive at Nabble.com.