Doodleverse/seg2map

JPEG images saved to CYMK colorspace isntead of RGB colorspacec

Closed this issue · 1 comments

The jpegs saved by gdal_translate_jpegs are not in the correct colorspace and are saved with 4 channels instead of 3.
Dan and I have worked on a solution to save them to the sRGB colorspace with 3 channels instead.

While we were troubleshooting I discovered that GDAL_JPEG_TO_RGB was set to NO which might have also been causing issues. Unfortunately, changing this variable did not solve the issue at the docs said it would https://gdal.org/drivers/raster/jpeg.html#raster-jpeg .

from osgeo import gdal

# Set GDAL_JPEG_TO_RGB to YES
gdal.SetConfigOption("GDAL_JPEG_TO_RGB", "YES")

# Check if the option is set to YES
jpeg_to_rgb_option = gdal.GetConfigOption("GDAL_JPEG_TO_RGB")
if jpeg_to_rgb_option == "YES":
    print("GDAL_JPEG_TO_RGB is set to YES")
else:
    print("Setting GDAL_JPEG_TO_RGB to YES failed")
file=r'C:\development\doodleverse\seg2map\seg2map\data\test1\ID_l8b00T_dates_2010-01-01_to_2010-12-31\multiband\2010\merged_multispectral.tif'
jpg_file = file.replace(".tif", ".jpg")
translateoptions= "-of JPEG -co QUALITY=100 -b 1 -b 2 -b 3"
creationoptions=["NUM_THREADS=ALL_CPUS", "COMPRESS=LZW", "TILED=YES"]
ds=gdal.Translate(destName=jpg_file, srcDS=file, options=translateoptions, creationOptions=creationoptions)
ds.FlushCache()
ds = None

to check the colorspace of an image, I use the imagemagick too 'identify' e.g. magick identify -verbose multiband0_USDA_NAIP_DOQQ_m_4012408_sw_10_1_20100629.jpg

I'm not closing this issue until its incorporated into a new release