Lets take, for example this jpeg image here


The image there is 400 x 300, or 120000 pixels and The file size of the image (on my computer) is shown to be 65171 bytes.

This means the computer stores about 2 pixels in every byte. How does it do this? Is it due to the same color pixels repeating in the image, so it only has to save the RGB data once, or is there some other trickery going on here?

  • 1
    $\begingroup$ What have you read? We require some research prior to asking a question, the Wikipedia page about JPEG is quite informative. $\endgroup$ – Evil Jul 16 '16 at 21:37
  • $\begingroup$ Anyway, JPEG is lossy compression (irreversible to original) and uses DCT transform in the way. If it took colors to store once it still would need the position of pixel to be stored. $\endgroup$ – Evil Jul 16 '16 at 21:41
  • $\begingroup$ Try to magnify the image, there are parts where small squares differs from the surrounding and are totally not fitting - JPEG artifacts, with distinguishable patterns. If the quality is better, the file gets bigger but artifacts are less visible up to non existent. It is where compression shaves bits off. $\endgroup$ – Evil Jul 16 '16 at 22:14

A colour image is typically digitalized using 256 levels for each of the 3 RGB channels. That gives 3 bytes per pixel. The trick to attain smaller file size is to apply some compression, to take advantage of the redundacy (neighbouring pixels tend to have similar colours). That depends on the image format. For example, PNG format applies a "lossless" compression (no information lost). JPEG format applies a more aggresive lossy compression (some information lost). BMP format is a format that does not (by default) compress; you can try to open your image and save it in BMP format and check that the size is approximately the expected (3 bytes per pixel). Other thing you can try is to generate a big "pure noise" image, and check that the size is also about 3 bytes per pixel (compression does not work here).

  • $\begingroup$ BMP uses RLE and other compression methods, just rarely implemented or usable... It depends on the image whether PNG or JPEG will be smaller. Maybe you could explain how JPEG compression works (maybe PNG too)? $\endgroup$ – Evil Jul 16 '16 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.