2
import matplotlib
import numpy as np

photo=plt.imread('Feynman.png')
plt.figure
plt.subplot(121)
plt.imshow(photo)
photo*=255
plt.subplot(122)
plt.imshow(photo)
  • Plot results in:
    • Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). and only displays an image in the first subplot

enter image description here

  • Used image

the image I use

0

1 Answer 1

3
  • The issue is photo*=255 is still an array of floats.
    • Look at the photo array.
    • Add photo = photo.astype(int) after photo*=255.
    • X in .imshow should be int type when the array is 0-255: (M, N, 3): an image with RGB values (0-1 float or 0-255 int)
photo = plt.imread('Feynman.png')

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 5))

print(photo[0][0])

ax1.imshow(photo)

photo*=255

print(photo[0][0])

photo = photo.astype(int)

print(photo[0][0])

ax2.imshow(photo)

[output]:
[0.16470589 0.16470589 0.16470589]
[42. 42. 42.]
[42 42 42]

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.