Converting RGBA to a grayscale image similar to LRO NAC

Hi,

I want to use drone imagery I have taken in the field at sites analogs to planetary surfaces such as Mars and the Moon as the input of a machine-learning Convolutional Neural Network (along with labels of specific features, in my case, the outline of boulders). I want the inputs to be grayscale (1-band) images because I would like the algorithm to be able to make predictions on 1-band imagery, as most of the spacecraft missions do not return multiple wavelength/bands products.

In the case I have more than one band available, as in my drone images (RGBA), I want to convert them to one band image to mimic the high-resolution one-band images returned from instruments such as LRO NAC, Framing Camera on the Dawn Spacecraft, HiRISE one-band product…).

When translating a color to grayscale image, most image-processing python libraries use the three RGB bands in the conversion (see Image Module - Pillow (PIL Fork) 9.4.0 documentation). Still, I was wondering if it would make more sense to convert only one of the bands to grayscale (e.g., the red band) to produce a more “real” planetary grayscale image?

I wonder if my question makes sense or matters that much, but I thought, why not asking?

Thanks for your help,
Best regards,
Nils

Makes sense. Using GDAL to just extract a single band is likely more than you need but it has this capability built-in. You can easily extract a single band, in your case band 1 (or Red). I recommend using a Anaconda or Miniconda environment to install GDAL on any OS. Once install simply run:

gdal_translate -b 1 in_image out_red.tif

If you want PNG or other format you must use a “output format” flag. GDAL does not respect setting the output format based on the output extension from the filename like some other convertors.

gdal_translate -b 1 -of PNG in_image out_red.png

For a little more advanced method to remove just the Alpha channel or remix the bands, see these threads:

The LROC NAC is a panchromatic sensor, so I would look into combining information from the three color channels in your data. It won’t be a great approximation of what LROC would see, but it should be closer than using one channel alone.

See Figure 15 in Robinson et al. (2010) for a plot of the NAC spectral response functions.

Edited to add link to docs for gdal_pansharpen.py, which may be useful: gdal_pansharpen.py — GDAL documentation

Thank you so much for your answers :slight_smile: I will go through the documentation you have shared.