[GRASS-user] integration of sample.c algorithms into r.resample

Maciej Sieczka tutey at o2.pl
Sat Aug 12 09:53:04 EDT 2006


Glynn Clements napisa?(a):

> I've attached a modified version of r.bilinear which does
> nearest-neighbour, bilinear and bicubic interpolation. It's only been
> lightly tested, but the case where the source and destination regions
> match (exact copy) has been tested. It could use some testing at more
> extreme scale factors.

> It would be possible to speed it up a bit, at the expense of
> simplicity, by caching the horizontal interpolates for each row. 
> However, even in its present form, it's still likely to be a lot
> faster than using the functions in sample.c.

Glynn,

I have tested and compared your r.bilinear to gdalwarp output. I took
care to run gdalwarp and r.bilinear with identical settings.

In case of naearest neigbor the output is identical.

In case of biliner and bicubic there is a minor difference between the 2
programs output, min=-0.000002 and max=0.000002. Exactly the same in
case of both methods. But this is propably due to the bug that r.in.gdal
forces FCELL on output http://intevation.de/rt/webrt?serial_num=4897
while your r.bilinear outputs DCELL. So I guess it is not important.

(A bit OT: what are the Grass equivalents for Gdal's
Int16,UInt16,UInt32,Int32,Float32,Float64,CInt16,CInt32,CFloat32,CFloat64?
 I'd like to put such note into r.out.gdal manual, it always puzzles me).

I was wondering what name should be given to the module. IMO it should
replace r.resample and r.bilinear should be removed. Is it acceptable
for Grass 6.3?

Here's the Spearfish scenario to reproduce my test:

g.region rast=slope -a
g.region res=15 -ap

r.bilinear input=slope output=gc_slope.nn method=nearest
r.bilinear input=slope output=gc_slope.bil method=bilinear
r.bilinear input=slope output=gc_slope.cub method=bicubic

### THE GDALWARP PART. -te switch lets us control the output extent to
duplicate r.bilinear settings.

r.out.gdal input=slope format=GTiff type=Float32 output=slope.tif

gdalwarp -te 589980 4913685 609000 4928040 -tr 15 15 -rn slope.tif
gdal_slope.nn.tif

gdalwarp -te 589980 4913685 609000 4928040 -tr 15 15 -rc slope.tif
gdal_slope.cub.tif

gdalwarp -te 589980 4913685 609000 4928040 -tr 15 15 -rb slope.tif
gdal_slope.bil.tif

### import gdalwarp output into spearfish
r.in.gdal input=/home/shoofi/gdal_slope.nn.tif output=gdal_slope.nn
r.in.gdal input=/home/shoofi/gdal_slope.bil.tif output=gdal_slope.bil
r.in.gdal input=/home/shoofi/gdal_slope.cub.tif output=gdal_slope.cub


### calculate the difference
r.mapcalc 'diff_nn=gdal_slope.nn-gc_slope.nn'
r.mapcalc 'diff_bil=gdal_slope.bil-gc_slope.bil'
r.mapcalc 'diff_cub=gdal_slope.cub-gc_slope.cub'

### see the difference:

r.info -r diff_nn
min=0.000000
max=0.000000

r.info -r diff_bil
min=-0.000002
max=0.000002

r.info -r diff_cub
min=-0.000002
max=0.000002

All looks good (TM).

Maciek




More information about the grass-user mailing list