In [9]:
# Python Imaging Library
import PIL 
from PIL import Image
In [48]:
# read sample image
pil_im = Image.open('images/empire.jpg')
print(pil_im)
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=490x689 at 0x2C4FA2B7C18>
In [16]:
# show Image
pil_im
Out[16]:
In [17]:
# clone image and convert to Grayscale
pil_im_gray = pil_im.convert('L')
print(pil_im_gray)
pil_im_gray
<PIL.Image.Image image mode=L size=490x689 at 0x2C4FA211AC8>
Out[17]:
In [18]:
#save garyscale picture
pil_im_gray.save("images/empire_gray.jpg")
In [19]:
import os

# create function that returns all files from path
def getImages(path):
    return [os.path.join(path, f) for f in os.listdir(path) if f.endswith(".jpg")]
In [23]:
# use the function over the images folder.
getImages("images")

# load the first image
Image.open(getImages("images")[0])
Out[23]: