Wie konvertieren Sie ein 3D -RGB -Numpy -Array, um zu schweben, ohne das Bild zu ändern?Python

Python-Programme
Anonymous
 Wie konvertieren Sie ein 3D -RGB -Numpy -Array, um zu schweben, ohne das Bild zu ändern?

Post by Anonymous »

Ich versuche ein Bild zu speichern, das sich in RGB -Pixelform befindet. Aus irgendeinem Grund, wenn ich Matplotlib.pyplot.imshow aufrufe, wird das Bild ordnungsgemäß angezeigt. Als ich mich entschied, alle Werte für Float zu ändern, ist das Bild vollständig geändert. Es macht für mich keinen Sinn. < /P>

Code: Select all

def display_image(pixels, name=""):
if name:
plt.imsave(name, array)
plt.imshow(array)

pixels = im.getdata()
pixelMap = im.load()
npImage = np.array(pixels).reshape(671, 450, 3)
display_image(npImage) ## great!

# things that I tried
display_image(npImage, "image.jpg") ## error, must be floats.

# changes the images
pixels = list(pixels) ## pixels var originally imagecore class
for index in range(len(pixels)):
pixels[index] = (float(pixels[index][0]), float(pixels[index][1]), float(pixels[index][2]))
display_image(npImage, "monaLisa.jpg") ## works but incorrect image

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post