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 the following link:
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 and will add 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 casts it into an array, and then simply adds 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 and is compatible with Python...