PIL

from PIL import Image, ImageOps


img = Image.fromarray(2d_arr).convert("L")

img = ImageOps.autocontrast(img)

img.save('2d_arr.png')

see shape

img.size

flipud

img.transpose(Image.FLIP_TOP_BOTTOM)

img to array

img = Image.open("f.png")

arr = np.asarray(img)

Float field to greyscale

norm_arr = (arr - arr.min()) / (arr.max() - arr.min())

norm_arr = (norm_arr * 255).astype('uint8')

img = Image.fromarray(norm_arr)

img.transpose(Image.FLIP_TOP_BOTTOM)

greyscale to color

img = Image.open("a.png")

img.convert('RGB')


rgbimg = Image.new("RGBA", img.size)

rgbimg.paste(img)

rgbimg.save("a_color.png")