I have the following code:
from PIL import Image
import numpy as np
a = np.ones((512, 256, 3)).astype(int)*255
image = Image.fromarray(a, "RGB")
image.save("test.png", "PNG")
I would expect this to result in a white image of size 512x256. Instead, I get this:

For some reason, this image is a series of bars rather than a solid color.
What am I doing wrong? Is it the format of the numpy array?
Instead of astype(int) use astype(np.uint8) or even better
a = np.full((512, 256, 3), 255, dtype=np.uint8)
The stripes you are seeing are the result of int values reinterpreted as sequences of uint8s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With