Quantizing an image with k-means clustering
Image processing is an important topic in which clustering has some application. It's worth pointing out that there are several very good image processing libraries in Python. scikit-image
is a sister project of scikit-learn. It's worth taking a look at if you want to do anything complicated.
A big point of this chapter is that images are data as well and clustering can be used to try to guess where some objects in an image are. Clustering can be part of an image processing pipeline.
Getting ready
We will have some fun in this recipe. The goal is to use a cluster to blur an image. First, we'll make use of SciPy to read the image. The image is translated in a three-dimensional array; the x
and y
coordinates describe the height and width, and the third dimension represents the RGB values for each image.
Begin by downloading or moving an .jpg
image to the folder where your IPython notebook is located. You can use a picture of yours. I use a picture of...