Exporting RGB image as GeoTIFF error

Hello,

is it somehow possible to export RGB image in GeoTIFF format in python ?
This code works for formats like PNG, JPG, BMP, TIFF but I am unable to export it as GeoTIFF.

    def write_rgb_image(bands, filename, format):
           image_info = ProductUtils.createImageInfo(bands, True, ProgressMonitor.NULL)
           im = ImageManager.getInstance().createColoredBandImage(bands, image_info, 0)
           JAI.create("filestore", im, filename, format)

    red = product.getBand('gamma3')
    green = product.getBand('gamma2')
    blue = product.getBand('gamma')
    write_rgb_image([red, green, blue], gamma_export, 'TIFF')

When I change TIFF for GeoTIFF I get the error :

INFO: org.hsqldb.persist.Logger: dataFileCache open start
Traceback (most recent call last):
  File "RGB_composit.py", line 91, in <module>
    rgb_OLCI()
  File "RGB_composit.py", line 87, in rgb_OLCI
    write_rgb_image([red, green, blue], gamma_export, 'GeoTIFF')
  File "RGB_composit.py", line 31, in write_rgb_image
    JAI.create("filestore", im, filename, format)
RuntimeError: java.lang.IllegalArgumentException: FileStore The specified format has no associated registered ImageCodec.

I’ve been looking all over the forum but I was unable to fix this. This error seems strange, since in SNAP GUI one can easily export RGB image as GeoTIFF.

Problem solved. Instead of using Java Advanced Imaging (JAI) library I have used snappy to generate GeoTIFF

ProductIO.getProductWriter('GeoTIFF')

Did you manage to create a GeoTiff that is viewable as an RGB image? My attempt creates a GeoTiff, which renders as transparent in a typical image viewer, the data is there as it is viewable in QGIS however its seems like the GeoTiff is badly formatted when compared the equivalent image produced from “Export view as image”.

def export_to_rgb(input_file):
    output_file = os.path.join(os.path.dirname(input_file), "test")
    product = ProductIO.readProduct(input_file)
    width = product.getSceneRasterWidth()
    height = product.getSceneRasterHeight()
    out_product = Product('rgb', 'GeoTIFF', width, height)
    writer = ProductIO.getProductWriter('GeoTIFF')
    ProductUtils.copyGeoCoding(product, out_product)
    out_product.setProductWriter(writer)
    ProductUtils.copyBand("RED", product, out_product, True)
    ProductUtils.copyBand("GREEN", product, out_product, True)
    ProductUtils.copyBand("BLUE", product, out_product, True)
    ProductIO.writeProduct(out_product, output_file, 'GeoTIFF')

Thanks for your help

Cheers

James