Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a giant GeoTIFF I'd like to convert to grayscale and add a gaussian blur to. As far as I know, GDAL can strip two of the three color bands and call it grayscale, which might work, but is there a better way? Imagemagick has both grayscale and gaussian blur functionality, but can not process georeferenced TIFFs (as far as I know). Any suggestions how I should go about doing this?

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

GDAL has a wonderful file format called VRT, which is an XML wrapper around one or more raster files.

One feature of VRTs is their ability to encode square convolution kernels for any given band. It does involve playing around with XML in a text editor (or programatically), but if you're already used to the GDAL tools, it shouldn't be too hard.

To illustrate, I took this image of some Ordnance Survey data from around the old OS building in Southampton:

Crown Copyright (c) 2012

And ran gdalbuildvrt to generate an initial VRT file:

gdalbuildvrt shirley.vrt shirley.tif

Then I replaced the <SimpleSource> elements with <KernelFilteredSource> elements, adding in the coefficients of a 5 x 5 Gaussian kernel:

  <SourceFilename relativeToVRT="1">shirley.tif</SourceFilename>
  <SourceProperties RasterXSize="400" RasterYSize="400" DataType="Byte" BlockXSize="256" BlockYSize="256" />
  <SrcRect xOff="0" yOff="0" xSize="400" ySize="400" />
  <DstRect xOff="0" yOff="0" xSize="400" ySize="400" />
  <Kernel normalized="1">
    <Coefs>0.0036630037 0.0146520147 0.0256410256 0.0146520147 0.0036630037
           0.0146520147 0.0586080586 0.0952380952 0.0586080586 0.0146520147
           0.0256410256 0.0952380952 0.1501831502 0.0952380952 0.0256410256
           0.0146520147 0.0586080586 0.0952380952 0.0586080586 0.0146520147
           0.0036630037 0.0146520147 0.0256410256 0.0146520147 0.0036630037

Then ran gdal_translate to convert to a TIFF:

gdal_translate -co TILED=YES shirley_gauss.vrt shirley_gauss.tif

Which gives me this image:

Crown Copyright (c) 2012

With its georeferencing data intact.

For the greyscale part, I suggest you use Quantum GIS and its good (if currently slightly quirky) Raster Calculator. Simply load up your blurred image, select Raster | Raster Calculator... and use the following expression:

(shirley_gauss@1 * 0.3) + (shirley_gauss@2 * 0.59) + (shirley_gauss@3 * 0.11)

Loading that image into QGIS, gives me:

Crown Copyright (c) 2012

Other coefficients can be used for the greyscale conversion, but those are a good starting point.

Also, it shouldn't matter whether you blur first then reduce, or the other way round.

share|improve this answer
+1 Very nice! And you're correct, the order of operations does not matter mathematically. In practice it might make a very slight difference due to integer rounding (or truncation) if intermediate results are saved as 24-bit images. –  whuber Feb 13 '12 at 17:08
I'll give this a try and let you know how it goes –  Corey Farwell Feb 14 '12 at 6:19
add comment

You're right, you'll lose georeferencing information when you process GeoTIFF in most 3rd party packages. One way of extracting the world georeferencing information from a GeoTIFF:

  1. Open ArcCatalog and gather the following properties from your GeoTIFF:
    • CellSize (X, Y)
    • Extent Left
    • Extent Top
  2. Create a text document named filename.tfw with the following 6 lines:

    • CellSize X
    • 0.0
    • 0.0
    • -CellSize Y
    • Extent Left
    • Extent Top

    it's important that the 4th parameter is negative and that you use the Top Left corner.

  3. When you convert your GeoTIFF in a 3rd party tool, you can provide this World file with the output image to regeoreference the image for ArcGIS.

Another way, is to use ArcCatalog convert the GeoTIFF into another Raster format, say, BMP, which forces the creation of the World file (usually .bpw) and the Auxiliary file containing projection (usually .aux.xml). You can discard the BMP itself but keep these additional files so that you can reapply them for your TIFF image.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.