Home > Software engineering >  How to convert 0-1 image float array to 0-255 int array
How to convert 0-1 image float array to 0-255 int array

Time:10-10

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

CodePudding user response:

  • 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 enter image description here

  • Related