[gdal-dev] Re: nodata - mask question

Dan Stahlke dan at gina.alaska.edu
Tue Feb 23 21:09:35 EST 2010


On Wed, 03 Feb 2010 09:54:10 -0500, Travis Kirstine wrote:

> I have a general question regarding how to handle the null values with 1
> band byte grey scale images.  Typically I will receive a image with
> pixels at the edges of a image with a  value of 0 however some of the
> interior pixel values (shadow areas) share the same pixel value.  My old
> approach was just to ignore the interior values and run gdalwarp
> indicating the source and target nodata as 0.
> 
> Is there a method currently available to distinguish between valid and
> invalid nodata values when they both share the same pixel value?

Travis,

I have created a tool to solve just this problem.  It works in Linux, and 
people have also gotten it to compile in Windows with some work.  You can 
download it from here:
    http://www.gina.alaska.edu/projects/gina-tools/

The utility of interest for your purpose is "gdal_trace_outline".  
Basically, you tell it various things about your image, such as the 
nodata value, whether the image has internal holes in it (like a 
doughnut), etc.  It traces the outline, uses some fuzzy logic to deal 
with raggedy edges due to shadows that hit the nodata value, and then 
outputs a WKT file and a mask file.  You can then use the mask to cut 
things out using ImageMagick or netpbm, or you could probably turn it 
into a mask band using GDAL's VRT format.

- Dan



More information about the gdal-dev mailing list