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()
감사
오류를 이미지로 추가 하시겠습니까? –