RGB
512x512
from PIL import Image
import numpy as np
import random
h, w = 512, 512
data = np.zeros((h, w, 3), dtype=np.uint8)
#Draw here
# data[y, x] = [r, g, b]
for y in range(100):
for x in range(100):
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
data[100+y, 100+x] = [r, g, b]
cv2.imwrite('my.png', data)
#or
img = Image.fromarray(data, 'RGB')
img.save('my.png')
img.show()