[FWTools] Converting a black border to transparent in geotifs

Frank Warmerdam warmerdam at pobox.com
Sun Feb 11 15:00:22 EST 2007


Simon Hook wrote:
> Hi,
> 
> I apologize if I sent a similar post last night but for some reason I 
> did not get a copy thro' the list.
> 
> I have some geotif images with a black border. I want to make the border 
> transparent. Is there a way to do this with FWTools?

Simon,

In part this depends on what software you want it to be transparent in.
In some software packages (like MapServer or OpenEV) you can pick a
"nodata value" such as 0 to be treated as transparent.  In some cases
the packages can also recognise nodata values as a kind of metadata from
the file.  The gdal_translate -a_nodata switch can be used to assign this
nodata value to an output file though it is only preserved in some formats.

eg.
gdal_translate -a_nodata 0 in.tif out.tif

Another approach to transparency is to add an alpha channel with
explicit transparency.  I think you could essentially assign all "zero"
pixels in an input greyscale image to have an alpha of zero in the output
using something like:

gdalwarp -srcnodata 0 -dstalpha in.tif out.

This whole area though is rife with challenges because:

  o many software packages don't automatically support nodata values.
  o some software packages don't recognise alpha bands for transparency
  o some file formats don't support saving nodata values.
  o some formats don't support alpha bands.
  o GDAL's "nodata" data model treats nodata values as independent for
    each band.
  o all black pixels will get treated as transparent, not just border values.

There are still a variety of issues I haven't addressed, but I think I'll
let you clarify what you want to do before I write more.

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    | President OSGeo, http://osgeo.org



More information about the FWTools mailing list