0

I don't understand : if we considerate the value 00001111 (15) is a byte and a RGB pixel (220,180,155) it's 3 bytes whatever the values of the pixel. so why when i reduce the values of my pixels (with bitshift operation or whatever) the size of my image is not = pixel numbers x 3. when i say "pixel numbers" i mean "pixel numbers bigger than fully black".

how the mechanism works ? is it counted in bits and then divided by eight as an average ? if i have a 3MB picture and i do a bitshift (factor 2 on each 3 RGB channel) i found a 300 KB picture.

Don't tell me 90% of my pixels turned fully black.
Thanks.

1 Answers1

1

If you shift all the pixel values right by 2 places, you will have around 1/4 as many shades of red as before, and around 1/4 as many greens and likewise for blues. That means overall you will have vastly fewer colours. That means your image may well have fewer than 256 colours which means it can be palettised. It also means it is likely to compress better because there will be more repetition of fewer unique sequences.


You can check if your image is palettised in several ways:

  • open it with PIL and check if image.mode contains a P
  • run exiftool on it and check if Colour Type is Palette
  • run ImageMagick on it with magick identify -verbose YOURIMAGE

You can count the number of unique colours in your image with ImageMagick using:

magick identify -format %k YOURIMAGE

Or you can do it in Python with the last part (entitled "Update") of this answer.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432