Hi all,
trying to rescale a map to 0:255 range, I run:
r.univar -g map
n=9599576
null_cells=0
cells=9599576
min=-1.55537462234497
max=274.231811523438
range=275.787186145782
mean=96.915776629461
mean_of_abs=96.915791505254
stddev=37.6540983935747
variance=1417.831125833
coeff_var=38.8523929778099
sum=930350363.3535346985
taking the max, i run:
r.mapcalc “map.invscaled = round((1.0 - map / 274.231811523438) * 255.0)”
But then:
r.info map.invscaled
±---------------------------------------------------------------------------+
| Layer: map.invscaled Date: Fri Mar 15 20:36:38 2013 |
| Mapset: PERMANENT Login of Creator: madi |
| Location: massimozia |
| DataBase: /home/madi/grassdata |
| Title: ( map.invscaled ) |
Timestamp: none |
|
Type of Map: raster Number of Categories: 0 |
Data Type: CELL |
Rows: 4181 |
Columns: 2296 |
Total Cells: 9599576 |
Projection: x,y |
N: 5170841.60115 S: 5045411.60115 Res: 30 |
E: 359567.587692 W: 290687.587692 Res: 30 |
Range of data: min = 0 max = 256 |
|
Data Description: |
generated by r.mapcalc |
|
Comments: |
round((1 - map / 274.23181) * 255) |
|
±---------------------------------------------------------------------------+ |
max = 256 must be an error in round() IMHO. Please let me know if I can’t see the obvious.
Thanks,
–
Best regards,
Margherita DI LEO
Postdoctoral Researcher
European Commission - DG JRC
Institute for Environment and Sustainability (IES)
Via Fermi, 2749
I-21027 Ispra (VA) - Italy - TP 261
Tel. +39 0332 78 3600
margherita.di-leo@jrc.ec.europa.eu
Disclaimer: The views expressed are purely those of the writer and may not in any circumstance be regarded as stating an official position of the European Commission.
On Fri, Mar 15, 2013 at 8:38 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
Hi all,
trying to rescale a map to 0:255 range, I run:
r.univar -g map
n=9599576
null_cells=0
cells=9599576
min=-1.55537462234497
max=274.231811523438
range=275.787186145782
mean=96.915776629461
mean_of_abs=96.915791505254
stddev=37.6540983935747
variance=1417.831125833
coeff_var=38.8523929778099
sum=930350363.3535346985
taking the max, i run:
r.mapcalc "map.invscaled = round((1.0 - map / 274.231811523438) * 255.0)"
try
r.mapcalc "map.invscaled = round((1.0 - ((map - $min) / $range)) * 255.0)"
Markus M
Thanks Markus,
On Fri, Mar 15, 2013 at 8:57 PM, Markus Metz <markus.metz.giswork@gmail.com> wrote:
try
r.mapcalc “map.invscaled = round((1.0 - ((map - $min) / $range)) * 255.0)”
This way :
Range of data: min = 0 max = 255
Still I don’t understand. Maybe I’m just tired…
–
Best regards,
Margherita DI LEO
Postdoctoral Researcher
European Commission - DG JRC
Institute for Environment and Sustainability (IES)
Via Fermi, 2749
I-21027 Ispra (VA) - Italy - TP 261
Tel. +39 0332 78 3600
margherita.di-leo@jrc.ec.europa.eu
Disclaimer: The views expressed are purely those of the writer and may not in any circumstance be regarded as stating an official position of the European Commission.
Margherita Di Leo wrote:
trying to rescale a map to 0:255 range, I run:
r.univar -g map
n=9599576
null_cells=0
cells=9599576
min=-1.55537462234497 <== ***NOTE ***
max=274.231811523438
range=275.787186145782
taking the max, i run:
r.mapcalc "map.invscaled = round((1.0 - map / 274.231811523438) * 255.0)"
The minimum value of the map is negative (-1.555...).
Your expression maps the maximum value to 0 and zero to 255, so the
minimum value will be mapped to slightly over 255. To be precise:
round((1.0 - (-1.55537462234497 / 274.231811523438)) * 255.0)
= round((1.0 - -0.005671751259288296) * 255.0)
= round(1.0056717512592883 * 255.0)
= round(256.4462965711185)
= 256
See Markus' reply for an alternative which maps the minimum and
maximum rather than zero and the maximum.
But note that it doesn't partition the data into 256 equal "bins", due
to the use of round(). The first and last bins (0 and 255) only cover
half the range of the other bins. The first and last bins each cover
1/510 of the range, while the others cover 1/255.
If you want equal-sized bins, use:
r.mapcalc "map.invscaled = int((1.0 - ((map - $min) / $range)) * 255.99999999999)"
--
Glynn Clements <glynn@gclements.plus.com>
On 15/03/13 20:38, Margherita Di Leo wrote:
Hi all,
trying to rescale a map to 0:255 range, I run:
r.univar -g map
n=9599576
null_cells=0
cells=9599576
min=-1.55537462234497
max=274.231811523438
range=275.787186145782
mean=96.915776629461
mean_of_abs=96.915791505254
stddev=37.6540983935747
variance=1417.831125833
coeff_var=38.8523929778099
sum=930350363.3535346985
taking the max, i run:
r.mapcalc "map.invscaled = round((1.0 - map / 274.231811523438) * 255.0)"
Just out of curiosity: why use r.mapcalc and not r.recode ? Is there any advantage of the former over the latter ?
Moritz
Hi,
On Mon, Mar 18, 2013 at 11:21 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:
Just out of curiosity: why use r.mapcalc and not r.recode ? Is there any advantage of the former over the latter ?
No I don’t think so, I just found the expression in an old message from the ML
http://osgeo-org.1560.n6.nabble.com/How-to-rescale-td3884695.html
thank you
–
Best regards,
Margherita DI LEO
Postdoctoral Researcher
European Commission - DG JRC
Institute for Environment and Sustainability (IES)
Via Fermi, 2749
I-21027 Ispra (VA) - Italy - TP 261
Tel. +39 0332 78 3600
margherita.di-leo@jrc.ec.europa.eu
Disclaimer: The views expressed are purely those of the writer and may not in any circumstance be regarded as stating an official position of the European Commission.