Surabhi Amit Chembra
Surabhi Amit Chembra

Reputation: 571

Image processing with numpy arrays

In the grayscale mode, 255 indicates white. So if all elements of the numpy matrix are 255, should not it be a white image?

l = np.full((184,184),255)
j = Image.fromarray(l,'L')
j.show()

I am getting a black-and-white vertical striped image as output instead of pure white image. Why is it so?

Upvotes: 1

Views: 688

Answers (1)

zipzit
zipzit

Reputation: 4027

The issue is the 'L' Mode. L = 8 bit pixels, black and white. The array you created is likely 32 bit values.

Try j = Image.fromarray(l, 'I') ## (32-bit signed integer pixels)

reference.

(note: Many thanks to you for introducing me to the Pillow Image module for Python with this posting...)

Complete test code:

from PIL import Image
import numpy as np
l = np.full((184,184),255)
j = Image.fromarray(m, 'I')
j.show()

Upvotes: 1

Related Questions