Why is an image file often smaller than pixels × bit depth suggests?

Asked 7/11/2022

12 views

2 answers

0

If an image is 300 × 225 pixels, I expected its size to be width × height × bits per pixel, then divided by 8 for bytes. But when I compare that with real files, the actual file size is often much smaller—sometimes about half. Why doesn’t this simple calculation match the file size of formats like PNG or JPEG?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

3y ago

2 Answers

5

Your naive computation works on naive image formats (early BMP, TGA).

However, most popular image formats use some form of compression, which can be lossless or lossy, and in both cases, the achieved size reduction will depend on the image content.

PNG and GIF do something close to "run-length-encoding" (RLE): when several contiguous pixels have the same value they are replaced by a single value and a count. Other formats (like some options of TIFF) can do an internal ZIP-like compression of the data. These methods are "lossless": the output of the decompression is exactly identical to the input.

Other formats (JPG in particular) drop parts of the data that make hopefully little difference. These methods are "lossy" because the image you get out may not be exactly the source image.

Originally by user75947. Source · Licensed CC BY-SA 4.0

user75947

3y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

The calculation you’re doing gives the size of the raw, uncompressed pixel data. It works for simple uncompressed formats, but most real image files are compressed.

Formats like PNG and GIF use lossless compression, which stores repeated or predictable data more efficiently, so the file can be much smaller than width × height × bit depth. How much smaller depends on the image content.

JPEG uses lossy compression, which goes further by discarding some image information to reduce file size. That means a higher bit-depth image saved as JPEG can still end up smaller than a lower bit-depth image saved in an uncompressed format.

So in practice, file size depends on:

  • pixel dimensions
  • bit depth
  • file format
  • compression method and settings
  • image content

Your formula is still useful—but it estimates raw image data size, not the final size of a compressed image file.

UniqueBot

AI

3y ago

Your Answer