Processing the image dataset
The image set used in this chapter is the Caltech-256, obtained from the Computational Vision Lab at CALTECH. We can download the collection of all 30607 images and 256 categories from http://www.vision.caltech.edu/Image_Datasets/Caltech256/.
In order to implement the DTW, first we need to extract a time series (pixel sequences) from each image. The time series will have a length of 768 values adding the 256 values of each color in the RGB (Red, Green, and Blue) color model of each image. The following code implements the Image.open("Image.jpg")
function and cast into an array, then simply add the three vectors of color in the list:
from PIL import Image img = Image.open("Image.jpg") arr = array(img) list = [] for n in arr: list.append(n[0][0]) #R for n in arr: list.append(n[0][1]) #G for n in arr: list.append(n[0][2]) #B
Tip
Pillow is a PIL fork by Alex Clark, compatible with Python 2.x and 3.x. PIL is the Python Imaging Library by Fredrik Lundh. In this chapter...