[gdal-dev] nearblack troubles

Even Rouault even.rouault at mines-paris.org
Wed Apr 27 13:26:28 EDT 2011


Le mercredi 27 avril 2011 17:57:26, Matt Wilkie a écrit :
> Hi All,
> 
> The geotiff here
> (http://www.maphew.com/Itches/Decollaring_with_nearblack) has two
> collars to be removed. The outermost consists of pure black (0,0,0)
> while the innermost is off-white (ranges from 240 thru 255). I used
> gdalsetnull[1] to change 0,0,0 to nodata,

nearblack doesn't take into account the nodata values. It just look at the 
pixel values.

> then ran `nearblack -white` on
> the result. I detect no difference in the output image even with a very
> large fuzz factor (-near 50) .

Yes, nearblack -white will stop as soon it encounters a black pixel...

> 
> What am I doing wrong?

Nothing, nearblack isn't designed for your use case. However it would be not 
difficult to hack the ProcessLine() method in nearblack.cpp to do both the white 
and black cases.

> 
> {{{
> d:\>cmd /version
> Microsoft Windows [Version 6.1.7600]
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
> 
> d:\>gdalinfo --version
> GDAL 1.8.0, released 2011/01/12
> 
> d:\>gdalinfo to-be-decollared.tif
> ...snip....
> Band 1 Block=375x7 Type=Byte, ColorInterp=Red
> Band 2 Block=375x7 Type=Byte, ColorInterp=Green
> Band 3 Block=375x7 Type=Byte, ColorInterp=Blue
> 
> d:\>copy to-be-decollared.tif 0-is-nodata.tif
> 
> d:\>gdalsetnull 0-is-nodata.tif
> Initial nodata for band  1      None
> Output nodata for band  1       0.0
> Initial nodata for band  2      0.0
> Output nodata for band  2       0.0
> Initial nodata for band  3      0.0
> Output nodata for band  3       0.0
> 
> d:\>gdalinfo 0-is-nodata.tif
> ...snip....
> Band 1 Block=375x7 Type=Byte, ColorInterp=Red
>     NoData Value=0
> Band 2 Block=375x7 Type=Byte, ColorInterp=Green
>     NoData Value=0
> Band 3 Block=375x7 Type=Byte, ColorInterp=Blue
>     NoData Value=0
> 
> d:\>nearblack -white -near 50 -o no-collar-white.tif 0-is-nodata.tif
> 
> d:\>gdalinfo no-collar-white.tif
> ...snip...
> Band 1 Block=64x64 Type=Byte, ColorInterp=Undefined
>     Description = Layer_1
>     Metadata:
>       LAYER_TYPE=athematic
> Band 2 Block=64x64 Type=Byte, ColorInterp=Undefined
>     Description = Layer_2
>     Metadata:
>       LAYER_TYPE=athematic
> Band 3 Block=64x64 Type=Byte, ColorInterp=Undefined
>     Description = Layer_3
>     Metadata:
>       LAYER_TYPE=athematic
> }}}
> 
> 
> [1]
> http://code.google.com/p/maphew/source/browse/trunk/gis/o4w_extras/bin/gdal
> setnull.py
> 
> thanks in advance for your time and thoughts,


More information about the gdal-dev mailing list