Implementing DTW
In this example, we will look for a similarity in 684 images from eight categories. We will use four imports of PIL, numpy, mlpy,
and collections
:
from PIL import Image from numpy import array import mlpy from collections import OrderedDict
Tip
First, we need to obtain the time series representation of the images and store it in a dictionary (data
) with the number of the image and its time series data[fn] = list
:
data = {} for fn in range(1,685): img = Image.open("ImgFolder\\{0}.jpg".format(fn)) arr = array(img) list = [] for n in arr: list.append(n[0][0]) for n in arr: list.append(n[0][1]) for n in arr: list.append(n[0][2]) data[fn] = list
Tip
The performance of this process will lie in the number of images processed, so beware of the use of memory with large datasets.
Then, we need to select an image for reference, which will be compared to all the other images...