Is there a known solution to convert images from having 3 channels (RGB) to having only one channel using PIL (or Scipy)
I tried converting the image to Grayscale
and saving as png as per the code below, the image still had 3 color channels.
from glob import glob
import os
import os.path
from PIL import Image
SIZE = 32, 32
# set directory
# os.chdir('..data/unprocessed_cats')
# filter all jpg and png images
IMAGE_FILES = glob('../data/validation/cats/*.jpg')
IMAGE_COUNTER = 1
print IMAGE_FILES
# iterate over files
for image_file in IMAGE_FILES:
# open file and resize
try:
im = Image.open(image_file)
except:
pass
im = im.resize(SIZE, Image.ANTIALIAS)
# save locally
output_filename = "%s.png" % IMAGE_COUNTER
# Grayscale
im.convert('LA').save(os.path.join('../data/validation', 'cats_processed', output_filename), "PNG")
# incriment image counter
IMAGE_COUNTER = IMAGE_COUNTER + 1