0

I'm using the GDAL command line tools gdal_warp and gdal_translate to convert RGB(A) GeoPDF images into GeoTIFF images. Unfortunately I found no config option that changes the RGB(A) color space to Grayscale.

I know it's possible to convert colors with gdal_calc.py (How to convert 4band RGB/A GeoTiff to 1band Gray GeoTiif?), but I would prefer a single step conversion.

With GDAL VRT we could use Python Pixel Functions to change our raster pixels, but I couldn't find any specific example. Is there anyone in this forum who has experience here? ...@EvenRouault?

5
  • What formula do you want to apply for the conversion from RGB into single band?
    – user30184
    Commented Apr 23 at 8:35
  • To be honest... I have no idea, Raster editing is a completely new territory for me. I have seen that Python Pillow uses "Floyd-Steinberg" dithering, but I have no special preferences.
    – christoph
    Commented Apr 23 at 9:17
  • 1
    There are some suggestions in gis.stackexchange.com/questions/71472/…. Transform into grayscale is not a common need in GIS. Writing a new pixel function for VRT feels like a good solution, but it feels also complicated. I think I would use some photo editor like GIMP myself.
    – user30184
    Commented Apr 23 at 9:27
  • Use the GDAL rgb2pct tool.
    – user2856
    Commented Apr 23 at 9:29
  • The rgb2pct tool, as documented gdal.org/programs/rgb2pct.html, does not make a grayscale image. It makes a single band paletted image. User can delete the color palette but the result would not be what is desired.
    – user30184
    Commented Apr 23 at 9:56

1 Answer 1

0

Wanted to know what AI is telling me and asked MS Copilot (aka ChatGPT), and the answer looked promising:

How to convert RGB(A) GeoPDF to Grayscale GeoTIFF with GDAL

enter image description here

2
  • 1
    The AI gives a lunatic and useless answer. It gives false information about what GDAL does by default, and it asks user to do odd things.
    – user30184
    Commented Apr 23 at 10:01
  • 2
    @user30184 you are right. At first glance it looked quite good, but on closer inspection it turned out to be a piece of junk 😊
    – christoph
    Commented Apr 23 at 10:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.