1
私の問題は、サンプル画像を撮って、外観を変えるために特定のRGB値を変更しようとしていることです。各ピクセルのデータを取得した後、3次元配列として保存してから、イメージに戻しますが、次のエラーが発生します。カラー画像(RGB)を、各ピクセルの3次元配列に変更した後、どのように作成できますか?
私はそれが戻って画像に変換する2次元配列を望んでいることを知っているが、私は色でそれを維持し、画像に戻ってそれを変換することができますかわかりません。何か案は?
from PIL import Image
import numpy as np
# Opens the image, giving it the call name im
img = Image.open("sample_images\sample_image_1.jpg")
# This function makes a list containing every RGB value of each pixel in sample_image_1
img_as_list = np.uint8(np.asarray(img))
print(img_as_list)
for x in img_as_list:
for rVal in x[0]:
if rVal <= 255:
rVal = 0
for bVal in x[1]:
if bVal <= 255:
bVal = 0
for gVal in x[2]:
if gVal <= 255:
gVal = 0
# Crate a new image from the list that i made from the picture
new_img = Image.fromarray(np.uint8(img_as_list),"L")
print(img_as_list)
new_img.show()
img.show()
ここに感謝
エラーを画像ではなくテキストとして追加します。 –