1

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?

2
  • confirm.. I got the same result using Canopy/ipython on Windows10. What's odd is when I change array size to 185,185, the lines all go diagonal. 184,184 = vertical lines. Commented Apr 11, 2018 at 16:54
  • yes, my project was not working due to this and finally after lots of debugging, I found this as the issue Commented Apr 11, 2018 at 16:57

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I used image.convert('L') to change it into required grayscale mode, ie, j.convert('L')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.