Last active
February 10, 2019 16:01
-
-
Save rish-16/7309db649f1fad1abbe3e5497d9c5e6a to your computer and use it in GitHub Desktop.
Converting coloured images to black and white images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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