简体   繁体   中英

How to display images with large pixel values with matplotlib?

matplotlib shows the white and black image, not the original image when I plot images of large pixel values.

You get white pixels because values above 1 for float and above 255 for int get clipped.

You can normalize the values to avoid clipping:

# generate (100x100x3) array of random float64 values between 0 and 100
x = np.random.uniform(0, 100, [100, 100, 3])

# normalize
x_norm = x / x.max()

# plot original vs. normalized
fig, ax = plt.subplots(1, 2)
ax[0].imshow(x)
ax[0].set_title('original')
ax[1].imshow(x_norm)
ax[1].set_title('normalized')

Output:

图片

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image = mpimg.imread("image.png")
plt.imshow(image)
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM