Project 3 Notes on Resizing Images with Python PIL

1. Vernon's Machine Vision book:

http://homepages.inf.ed.ac.uk/rbf/BOOKS/VERNON/toc.htm

2. Pillow

3. for loops

4. glob.glob()

How to Use Image.resize()

  • Pass a tuple of (width, height) to the argument size.
  • Pass the filter for resample.
    Resampling Filters
    -NEAREST (which is used by default)
    -BOX
    -BILINEAR
    -HAMMING
    -BICUBIC
    -LANCZOS
  • For images created by the library itself (via a factory function, or by running a method on an existing image), this attribute is set to None.
  • If the image was not read from a file, it is set to None.
  • Image size needs to be specified as integers.
In [1]:
import sys
sys.version
Out[1]:
'3.6.9 (default, Oct  8 2020, 12:12:24) \n[GCC 8.4.0]'
In [2]:
pip uninstall PIL
WARNING: Skipping PIL as it is not installed.
In [3]:
pip install Pillow==8.1.0
Requirement already satisfied: Pillow==8.1.0 in /usr/local/lib/python3.6/dist-packages (8.1.0)
In [4]:
import PIL
PIL.__version__
Out[4]:
'8.1.0'
In [5]:
from google.colab import drive
drive.mount('/content/drive')
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
In [6]:
import shutil
shutil.unpack_archive('/content/drive/My Drive/pallasite.zip', '/content/drive/My Drive')
In [7]:
from PIL import Image
im = Image.open('/content/drive/My Drive/pallasite/Esquel.jpg')
print(im.format, im.size, im.mode)
im
JPEG (2736, 2014) RGB
Out[7]: