I tried to create a grey 3x3 pixel image in python, however the result is always a black image with several coloured pixels.
What I tried:
import numpy as np
from PIL import Image
greyimg = np.array([[[128]*3]*3]*3)
print(greyimg)
Image.fromarray(greyimg, 'RGB').save("test_grey.png")
What I expected: a grey 3x3 image
What I got: a coloured image
CodePudding user response:
import numpy as np
from PIL import Image
import cv2
greyimg = np.array([[[128]*3]*3]*3,dtype=np.uint8)
print(greyimg)
Image.fromarray(greyimg, 'RGB').save("test_grey.png")