我一直在嘗試將影像 (.png) 分解為串列,編輯串列,然后將編輯后的影像另存為檔案。
編輯影像并將其恢復到陣列后,可以mpl.imshow(image)正確顯示新影像,但是嘗試將其另存為檔案會導致影像空白。
我認為缺陷在于標記的行 # <-- Estimated point of failure,但我研究了該命令,找不到解決問題的方法。我已經使用 來檢查重建的陣列print(),似乎沒有什么例外。
關于如何以檔案形式正確保存我編輯的影像的任何想法將不勝感激。
謝謝你的幫助,Lochlann F.
import numpy as np
import matplotlib.pyplot as mpl
from PIL import Image
# Desconstruct the image into an editable list
img = Image.open('mini.png')
my_dot_array = np.asarray(img)
my_dot_list = my_dot_array.tolist()
my_dot_list[0][0] = [30, 220, 90, 255] # <-- Attemp a small edit to a pixel in the image
# Reconstuct the image into a saved .png file
my_dot_array = np.asarray(my_dot_list)
img = Image.fromarray(my_dot_array, mode='RGBA') # <-- Estimated point of failure
img = img.save('updated_mini.png')
# Display the resulting image
mpl.imshow(my_dot_array)
mpl.show()
#print(my_dot_array)
uj5u.com熱心網友回復:
我想你是一個人。上面的行需要第二個引數dtype=np.uint8:
my_dot_array = np.asarray(my_dot_list, dtype=np.uint8)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/354283.html
上一篇:“串列物件”沒有屬性“名稱”
下一篇:Swift全名陣列排序
