Implementing Principal Component Analysis (PCA) in OpenCV

One of the most common dimensionality reduction techniques is called 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 grayscale image of height m and width n by stacking all of the columns, we get a (feature) vector of length m x n x 1. The value of the ith element in this vector is the grayscale value of the ith 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 x n images. Chances ...

Get Machine Learning for OpenCV 4 - Second Edition 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.