Open In Colab

Project 5 Notes on Image Processing with Python

  • Reading, displaying and saving an image by using PIL
  • Reading, displaying and saving an image by using matplotlib
  • Converting an image from png to jpg by using cv2
  • Resizing
  • Face morphing
  • Seam carving

Reading, Displaying and Saving an Image with PIL

In [1]:
import PIL
PIL.__version__
Out[1]:
'8.1.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]:
from PIL import Image
deer = Image.open('/content/drive/My Drive/d.png')
In [7]:
print(deer.format, deer.mode, deer.size)
PNG RGB (500, 377)
In [8]:
deer
Out[8]:
In [9]:
deer_convert = deer.convert('RGB')
deer_convert.save('/content/drive/My Drive/deer.jpg')
In [10]:
deer_resize = deer.resize((deer.width//2, deer.height//2))
deer_resize.save('/content/drive/My Drive/deer_resize.jpg')
In [11]:
deer_resize
Out[11]:
In [12]:
liang = Image.open('/content/drive/My Drive/liang.png')
liang_resize = liang.resize((liang.width//2, liang.height//2))
liang_resize.save('/content/drive/My Drive/liang_resize.png')
In [13]:
liang
Out[13]: