pythonimagejpeg2000

jpg2000 to jpg with pgmagick on Windows comes out as grayscale


I need convert/load jpg2000 images (24 BIT RGBI True Color) to png/jpg for further usage and struggled quite a bit to get them loaded at all on windows. Succeeded with a pgmagic installation on windows, but the RGBI images come out as grayscale.

Output image generated with:

from pgmagick import Image
img = Image("path")
img.write('output.jpg')

What am I missing here?

enter image description here


Solution

  • Found the answer myself:

    I had to use osgeo:

    from osgeo import gdal
    from PIL import Image
    
    dataset = gdal.open("path", gdal.GA_ReadOnly)
    img = dataset.ReadAsArray()
    img_trnsp = img.transpose()
    final_image = Image.fromarray(img_trnsp)