Reputation: 45
Why this code plot different images?
from PIL import Image
import numpy as np
x = (np.random.random((32,32))*255).astype(np.int16)
img1 = Image.fromarray(x, mode='L')
img2 = Image.fromarray(x)
plt.imshow(img1, cmap='gray')
plt.imshow(img2, cmap='gray')
see images:
Upvotes: 0
Views: 1312
Reputation: 207445
PIL requires L
mode images to be 8-bit, see here. So, if you pass in your 16-bit image, where every high byte is zero, every second pixel will be black.
Upvotes: 2