Create an art or image by yourself using arrays and Numpy.
Creating greyscale images with NumPy and PIL
Greyscale images are handled slightly differently. Because there is only one channel, there is no need to create a 3-dimensional array, you should use a 2-dimensional array instead:
import numpy as np
from PIL import Image
array = np.zeros([100, 200], dtype=np.uint8)
# Set grey value to black or white depending on x position
for x in range(200):
for y in range(100):
if (x % 16) // 8 == (y % 16) // 8:
array[y, x] = 0
else:
array[y, x] = 255
img = Image.fromarray(array)
img.save('testgrey.png')
In this case, we have created a chequerboard image:
Comments
Post a Comment