Original vs 16 colors

Hello,
In which way the image is compressed?

To my understanding, the colors is compressed to 16 colors, but the X_recovered itself isn’t compressed. I know it is absolutely compressed, any hints are appreciated.
Screenshot 2023-11-27 at 8.07.30 PM

Hello @Daniel_Zhao

Your understanding is correct.

However, X_recovered.size does not show you the number of colors. Try to find the number of colors in X_recovered!

Cheers,
Raymond

How the number of color make the image small?

  1. Original Image Representation:
  • In digital images, each pixel’s color is typically represented in the RGB (Red, Green, Blue) format.
  • Each RGB channel can have 256 different intensities (from 0 to 255), usually encoded in 8 bits (2^8 = 256).
  • So, for a 128x128 pixel image, each pixel requires 24 bits (8 bits for each RGB channel).
  1. Compressed Image Representation:
  • Instead of using 256 different intensities for each channel, the idea is to reduce the number of colors to K (16 in your case).
  • This is done by finding the K most representative colors (centroids) of the image. Each pixel is then assigned to the nearest centroid color.
  • The compressed image uses these K colors instead of the full spectrum of colors.

How to check how many colors for each image?

Hi @Daniel_Zhao,

Each value in the picture array (compressed or not) is a color value. In other words, to see how many different colors are used, you go through the array, and make a count of how many different values are ever used.

You can write loops to do it.

Or you may study this - numpy.unique. Just go to its documentation for how it works and what it does, and it should help you.

Cheers,
Raymond