Home > Software engineering >  PIL won't load RGB Image
PIL won't load RGB Image

Time:07-03

I am trying to load this image into python (I provided a link because its 75mb): https://drive.google.com/file/d/1usiKRN1JQaIxTTo_HTXPwUj8LeyR8CDc/view?usp=sharing

My current code is below, it loads the image and when you png.show() the image it displays it in RBG but when converted to a numpy array its shape is only (h, w) not (h, w, 3) for RGB.

Code:

import numpy as np
from PIL import Image
Image.MAX_IMAGE_PIXELS = 233280000

png = Image.open('world.png')
png.show()
png = np.array(png)

print(png.shape)

CodePudding user response:

Try this instead:

import numpy as np
from PIL import Image
Image.MAX_IMAGE_PIXELS = 233280000

png = Image.open('world.png').convert('RGB')
png.show()
png = np.array(png)

print(png.shape)
  • Related