# [gdal-dev] gdalwarp vs gdal_translate for resizing images

Even Rouault even.rouault at spatialys.com
Fri Oct 28 05:21:27 PDT 2016

```Le vendredi 28 octobre 2016 10:37:27, Rutger a écrit :
> While on the subject, i'm not aware of the implementation details of GDAL's
> bilinear algorithm**. But normally you go from four source points/pixels to
> a new one. How is this handled in extreme downsampling cases like Travis is
> doing?

All resampling methods (except Gauss but that should likely be fixed, and
nearest neighbour of course) since GDAL 2.0 take into account all the needed
source pixels.

For a bilinear interpolation without resampling (or with oversampling), the
weight function (in 1D) is :
1 - |x| if |x| <= 1
0 otherwise

where x is the distance of the center of the target pixel (considered in the
dimensions of the source image) to the center of the source pixel considered

When downsampling by a factor of N, it is generalized as:
(1 - |x/N|)/N if |x| <= N
0 otherwise
So you have 2*N pixels taken into account

So when downsampling by a factor of 20, it is (2*20)^2 = 1600 source pixels
taken into account for bilinear.

Example, let's consider test.asc being:

ncols        6
nrows        6
xllcorner    0
yllcorner    0
cellsize     0
0   0   0   0   0   0
0   100 0   0   0   0
0   0   0   0   0   0
0   0   0   0   0   0
0   0   0   0   0   0
0   0   0   0   0   0

\$ gdal_translate test.asc /vsistdout/ -of aaigrid -r bilinear -outsize 50% 50%
ncols        3
nrows        3
xllcorner    0.000000000000
yllcorner    0.000000000000
cellsize     0.000000000000
18 5 0
5 2 0
0 0 0

This is the same result you'd got by using imagemagick
"convert -filter triangle -resize 50% in.tif out.tif"

Whereas average (after https://trac.osgeo.org/gdal/changeset/35991, so this
email took me all the morning lol) will return:

\$ gdal_translate test.asc /vsistdout/ -of aaigrid -r average -outsize 50% 50%
ncols        3
nrows        3
xllcorner    0.000000000000
yllcorner    0.000000000000
cellsize     0.000000000000
25 0 0
0 0 0
0 0 0

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
```