[Gdal-dev] Re: GDAL Decimation

Frank Warmerdam warmerdam at pobox.com
Wed Nov 12 14:19:38 EST 2003


Roger Bedell wrote:
> Frank,
> 
> Thanks for GDAL – great stuff. If I could bother you for a second, just 
> one question at the moment (actually two or three on the same subject).

Roger,

I have taken the librety of also distributing my answer to the gdal-dev
list as I have had other questions on this topic.

> I just want to decimate an image to several different resolutions, kind 
> of like the Overview stuff. I’m used to using the Intel Image Processing 
> Library, which has an excellent decimation using something they call 
> Super Sampling. You may not have this, but how can I decimate whilst 
> specifying at least Cubic Interpolation?
> 
>  
> 
> 1)       I cannot get the Overview stuff to work, at least with the Jpeg 
> driver. I get an OVR file, but it seems to be unreadable. Perhaps I 
> don’t understand what I am doing.

The .ovr file should be a TIFF file with the overviews in it.  If you
only generate one overview then it should be a pretty standard file,
though I don't know for sure if I write georeferencing info or not.

> 2)       With the TIFF driver, I haven’t the slightest idea of how to 
> get each Overview into a separate usable TIFF file so I can save it.

If you create the overviews, you can just use gdal_translate to get them
out.

For instance, in this example, I add a 4x4 reduced overview to a file
using averaging.  Checking with gdalinfo I see the overview is 128x128.
So then I use gdal_translate to generate an output file that size.  GDAL
should utilize the overview layer when exporting, and you should get
the averaged down data.

warmerda at gdal2200[22]% gdaladdo -r average utm.tif 4
0...12...21...31...40...50...62...71...81...90...100 - done.
warmerda at gdal2200[23]% gdalinfo utm.tif
Driver: GTiff/GeoTIFF
Size is 512, 512
Coordinate System is:
PROJCS["NAD27 / UTM zone 11N",
     GEOGCS["NAD27",
         DATUM["North_American_Datum_1927",
             SPHEROID["Clarke 1866",6378206.4,294.9786982138982,
                 AUTHORITY["EPSG","7008"]],
             AUTHORITY["EPSG","6267"]],
         PRIMEM["Greenwich",0],
         UNIT["degree",0.0174532925199433],
         AUTHORITY["EPSG","4267"]],
     PROJECTION["Transverse_Mercator"],
     PARAMETER["latitude_of_origin",0],
     PARAMETER["central_meridian",-117],
     PARAMETER["scale_factor",0.9996],
     PARAMETER["false_easting",500000],
     PARAMETER["false_northing",0],
     UNIT["metre",1,
         AUTHORITY["EPSG","9001"]],
     AUTHORITY["EPSG","26711"]]
Origin = (440720.000000,3751320.000000)
Pixel Size = (60.000000,-60.000000)
Corner Coordinates:
Upper Left  (  440720.000, 3751320.000) (117d38'28.21"W, 33d54'8.47"N)
Lower Left  (  440720.000, 3720600.000) (117d38'20.79"W, 33d37'31.04"N)
Upper Right (  471440.000, 3751320.000) (117d18'32.07"W, 33d54'13.08"N)
Lower Right (  471440.000, 3720600.000) (117d18'28.50"W, 33d37'35.61"N)
Center      (  456080.000, 3735960.000) (117d28'27.39"W, 33d45'52.46"N)
Band 1 Block=512x16 Type=Byte, ColorInterp=Gray
   Overviews: 128x128
warmerda at gdal2200[24]% gdal_translate -outsize 128 128 utm.tif ov.tif
Input file size is 512, 512
0...10...20...30...40...50...60...70...80...90...100 - done.

> So, I started working with the GDALDatasetRasterIO method. I can’t seem 
> to get it to work to decimate, and besides, it doesn’t seem to have any 
> way of setting the interpolation scheme.

Right, the RasterIO() methods support only simple decimation, not any
of the other overview generation strategies (averaging) or general image
warping resamplers (like bilinear and cubic resampling).

If you wanted to utilize the warping resamplers, just use gdalwarp.  For
instance, the following would produce a 128x128 downsampled image using
cubic convolution.

gdalwarp -ts 128 128 -rc utm.tif ov2.tif

> If you could steer me in the right direction, I’d be very happy. By the 
> way, calling GDAL from .NET seems to work just fine.

Cool!

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent






More information about the Gdal-dev mailing list