Skip to content

Instantly share code, notes, and snippets.

@rish-16
Last active February 10, 2019 16:01
Show Gist options
  • Save rish-16/7309db649f1fad1abbe3e5497d9c5e6a to your computer and use it in GitHub Desktop.
Save rish-16/7309db649f1fad1abbe3e5497d9c5e6a to your computer and use it in GitHub Desktop.
Converting coloured images to black and white images
from PIL import Image
import numpy as np
gray_images_train = []
# `train_images` is an array containing the image file paths
for img in train_images:
img = Image.open(img)
gray = img.convert('L')
gray_images_train.append(gray)
gray_images_train = np.array(gray_images_train, dtype=np.float32)
np.save('gray_images_train.npy', gray_images_train)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment