[gdal-dev] How to convert png color to png/tiff black and white

LE LAMER Romain rlelamer at hotmail.fr
Sun Dec 29 07:47:02 PST 2019


Hi,

I need to convert 524 288 color png tiles to black and white png.

=> The lands always have the 2 colors RGB (RGBA?) 59,89,95,255 and / or 60,89,96,255.
=> The sea always has the colors RGB 109,178,200,255 / 138,193,212,255 and 161,205,220,255.

Some tiles contain only land, others only sea and still others contain land and at least 1 color of the sea ...

I use gdal_translate to georeference and assign a projection to each tile (via script) with the following command (and it works perfectly):
gdal_translate -a_srs EPSG: 4326 -a_ullr <ulx> <uly> <lrx> <lry> input.png output.tiff

I have read and reread, in every way, the gdal_translate help with the args -b and -mask and I don't understand how to use it ...

I need all the sea colors to always be Black and all the lands colors to be White.
(I polygonize each tile afterwards)

How can I do this via gdal_translate or other gdal program?

Thanks for your help


PS:
What gdalinfo gives me for a random tile (original png)
gdalinfo map_11_0_309.png
Driver: PNG/Portable Network Graphics
Files: map_11_0_309.png
Size is 256, 256
Coordinate System is `'
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  256.0)
Upper Right (  256.0,    0.0)
Lower Right (  256.0,  256.0)
Center      (  128.0,  128.0)
Band 1 Block=256x1 Type=Byte, ColorInterp=Palette
  Image Structure Metadata:
    NBITS=2
  Color Table (RGB with 4 entries)
    0: 60,89,96,255
    1: 109,178,200,255
    2: 138,193,212,255
    3: 161,205,220,255

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20191229/47c55bde/attachment.html>


More information about the gdal-dev mailing list