Use Principal Component Analysis to compress the same images
We use some image processing and machine learning libraries to implement color quantization by using PCA algorithm.
Their names and installation instructions are as follows:
-
numpy
Open the terminal and input: pip3 install numpy
-
matplotlib
Open the terminal and input: pip3 install matplotlib
-
imageio
Open the terminal and input: pip3 install imageio
-
PIL
Open the terminal and input: pip3 install pillow
Python 3.7.2
We use PCA algorithm to quantize the images. Firstly using numpy to transform the original image to 2D array on RGB and then reconstruct 2D matrix using PCA algorithm. Finally, combine RGB to color image and using matplotlib to display the quantized images with different values.