9951 explained code solutions for 126 technologies


python-pillowHow to create image from an array


from PIL import Image
import numpy as np

data = np.random.randint(1, 255, (100,300))
im = Image.fromarray(data, mode="L")
im.show()ctrl + c
PIL

import Pillow package modules

np.random.randint(

generate matrix of the given shape with random integers in the given range

Image.fromarray(

creates image from given array

mode="L"

creates image in black and white mode

.show()

displays resulting image