Image.fromarray
을 사용하여 백분율 매트릭스를 회색 음영 이미지로 저장하려고합니다. 그것은 임의의 행렬에서 작동하는 것으로 보이지만 특정 행렬 (원이 표시되어야하는 곳)에서는 작동하지 않습니다. 아무도 내가 뭘 잘못 설명 할 수 있습니까?Image.fromarray가 검은 색 이미지를 생성합니다.
from PIL import Image
import numpy as np
radius = 0.5
size = 10
x,y = np.meshgrid(np.linspace(-1,1,size),np.linspace(-1,1,size))
f = np.vectorize(lambda x,y: (1.0 if x*x + y*y < radius*radius else 0.0))
z = f(x,y)
print(z)
zz = np.random.random((size,size))
img = Image.fromarray(zz,mode='L') #replace z with zz and it will just produce a black image
img.save('my_pic.png')
255로 크기를 조정하고'uint8/16' dtypes를 사용해야합니다. – Divakar
그러나'zz'는 0과 1 사이의 값을 갖는 행렬이기도하며 괜찮습니다. – flawr
'zz'가 작동하지만'z'는 작동하지 않는다고 말하는가? – Divakar