Hello, I have version 3.6.2 of GDAL and I need to crop an image using a contour 
from a GML file, so far there is no problem.

The problem begins when the original image is a GEOTIFF with transparency and 
it generates a cropped image, the information of both images is a little lower.

The color table changes from having 2 values to having 256, this causes it to 
lose transparency although it has the label "Mask Flags: PER_DATASET ALPHA" 
which indicates that it has an alpha channel.

My question is, why does the color table change?, and is there any parameter 
that can be used with gdalwarp or gdal_translate to avoid this and keep the 
image transparent?



I use this command:

gdalwarp.exe -cutline fichero.gml -crop_to_cutline -dstalpha ficheroIN 
ficheroOUT --config GDAL_DATA rutaGDAL


ORIGINAL IMAGE

Driver: GTiff/GeoTIFF

Size is 5616, 3655

…

Metadata:

  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)

  TIFFTAG_XRESOLUTION=300

  TIFFTAG_YRESOLUTION=300

Image Structure Metadata:

  INTERLEAVE=BAND

Corner Coordinates:

…

Band 1 Block=5616x1493 Type=Byte, ColorInterp=Palette

  Image Structure Metadata:

    NBITS=1

  Color Table (RGB with 2 entries)

    0: 0,0,0,255

    1: 255,255,255,255



CROPPED IMAGE

Driver: GTiff/GeoTIFF

Size is 5605, 2689

….

Metadata:

  TIFFTAG_DATETIME=2024:02:09 08:49:12

  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)

  TIFFTAG_SOFTWARE=Microsoft Windows Photo Viewer 10.0.19041.1

  TIFFTAG_XRESOLUTION=300

  TIFFTAG_YRESOLUTION=300

Image Structure Metadata:

  COMPRESSION=LZW

  INTERLEAVE=PIXEL

Corner Coordinates:

….

Band 1 Block=5605x1 Type=Byte, ColorInterp=Palette

  Mask Flags: PER_DATASET ALPHA

  Color Table (RGB with 256 entries)

    0: 0,0,0,255

    1: 255,255,255,255

    2: 0,0,0,255

    3: 0,0,0,255

….

  252: 0,0,0,255

  253: 0,0,0,255

  254: 0,0,0,255

  255: 0,0,0,255



I await your response, thank you and regards.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to