Skip to content

Instantly share code, notes, and snippets.

@jeanmidevacc
Created January 18, 2020 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanmidevacc/40a7fcdf5bcd5d038bb2f2725b111c0e to your computer and use it in GitHub Desktop.
Save jeanmidevacc/40a7fcdf5bcd5d038bb2f2725b111c0e to your computer and use it in GitHub Desktop.
from PIL import Image
def build_mlimage(path, config_resize = (100,50), is_bw = True):
# Access the image
img = Image.open(path)
# Resizing and conversion in black and white (if necessary)
if is_bw:
newimg = img.resize(config_resize, Image.ANTIALIAS).convert('L')
else:
newimg = img.resize(config_resize, Image.ANTIALIAS)
# Flatten the image during the return
return np.array(newimg).flatten().tolist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment