Implementing Principal Component Analysis (PCA) in OpenCV

One of the most common dimensionality reduction techniques is called Principal Component Analysis (PCA).

Similar to the 2D and 3D examples shown earlier, we can think of an image as a point in a high-dimensional space. If we flatten a 2D image of height m and width n by stacking all the columns, we get a (feature) vector of length m n 1. The value of the i-th element in this vector is the grayscale value of the i-th pixel in the image. Now, imagine we would like to represent every possible 2D grayscale image with these exact dimensions. How many images would that give?

Since grayscale pixels usually take values between 0 and 255, there are a total of 256 raised to the power of m n ...

Get Machine Learning for OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.