PIL과 NumPy와 친구가 여기에 있습니다 :
from PIL import Image
import numpy
pixels = [
[(54, 54, 54), (232, 23, 93), (71, 71, 71), (168, 167, 167)],
[(204, 82, 122), (54, 54, 54), (168, 167, 167), (232, 23, 93)],
[(71, 71, 71), (168, 167, 167), (54, 54, 54), (204, 82, 122)],
[(168, 167, 167), (204, 82, 122), (232, 23, 93), (54, 54, 54)]
]
# Convert the pixels into an array using numpy
array = numpy.array(pixels, dtype=numpy.uint8)
# Use PIL to create an image from the new array of pixels
new_image = Image.fromarray(array)
new_image.save('hello.png')
편집 :
다음 게시물을 참조
이 방법을 사용하여 임의의 픽셀 이미지를 만드는 작은 목록 이해 재미 :
from PIL import Image
import numpy as np
import random
def random_img(output, width, height):
import random
array = np.random.random_integers(0,255, (width,height,3))
array = np.array(array, dtype=np.uint8)
img = Image.fromarray(array)
img.save(output)
random_img('a.png', 50, 50)
감사합니다. – Gray
좋아요! 내 게시물을 편집하여 임의의 픽셀 값으로 이미지를 만드는 작은 목록 이해 재미. – Jebby
큰 답변이지만 큰 해상도의 경우 시간이 많이 걸립니다 (임의의 픽셀 1). 그래서 최적화해야합니다. 내가 만든 유일한 수정은 목록 이해력과 함수 width * height *를 3 번 호출하는 대신 방금 한 번 호출했기 때문입니다. array = np.random.random_integers (0,255, (width, height, 3)). 멋진 하루 되십시오 :) –