Skip to content

Instantly share code, notes, and snippets.

@topin89
Created August 21, 2018 11:37
Show Gist options
  • Save topin89/4c73b92afe1f5a68fbf7faa6976d3031 to your computer and use it in GitHub Desktop.
Save topin89/4c73b92afe1f5a68fbf7faa6976d3031 to your computer and use it in GitHub Desktop.
Custom lookup table for Pillow and Numpy
from PIL import Image
import numpy as np
IM_LUT=np.array([(255,255,255,255),(0,0,0,255),
(255,0,0,255),(0,255,0,255),(0,0,255,255),
(255,255,0,255),(255,0,255,255),(0,255,255,255),
(128,0,0,255),(0,128,0,255),(0,0,128,255),
(128,128,0,255),(128,0,128,255),(0,128,128,255),
(128,255,0,255),(128,0,255,255),(0,128,255,255),
(255,128,0,255),(255,0,128,255),(0,255,128,64),]
).astype(np.uint8)# Your lut here, preferebally 256 entries
image_data = np.zeros((width, height), dtype=np.uint8) #Your data here
Image.fromarray(IM_LUT[image_data], 'RGBA').save("image.bmp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment