Tuesday, April 2, 2019

Image File Size for Dummies

bit depth of an image
Bit depth of an image
When the Antisocial Network staff find content that seems suspicious, they'll do the research the freelancer who wrote it probably should have done (instead of pretending to do it). That way you can be confident that we at least tried to get it right...  which brings us to today's DotD nomination. If the truth be told, we were looking for something else when we ran across Stephen Lilley trying to explain something for Techwalla.com. Lilley apparently thought he was in his wheelhouse explaining "How Pixels Are Converted to Bytes"... but he wasn't.

Lilley, a film school grad, has been here before, usually trying to answer HDTV questions (and getting it half-right at best). This time he's ducked into the world of mathematics, with a little computerese mixed in. Unfortunately, he was out of his depth in both cases. He started off OK – clumsy, but essentially correct – by telling his readers,
"When a person talks about converting 'pixels' to 'bytes,' he is not talking about a literal conversion. What he is referring to is a mathematical calculation that determines how large an image file will be based on its resolution."
Unfortunately, Steve didn't publish his references, so we're not certain where to lay the blame for his misinterpretation. Yes, he's right about what the conversion means, but he's only half right about the "resolution" part. Resolution is, essentially, pixels per inch; so we really need to know the image dimensions in pixels, not its resolution. And that's not just being pedantic.

Steve did OK up to a point in outlining the necessary calculations, with the exception of a glaring error due to his (and his copy editor's) likely innumeracy:
"As a rule, there are 16 bits of file size per pixel. This means that there are 8 bits per byte of file size, as 2 bits equals 1 byte [bolding ours]. In keeping with things that are equal, this then means that there are 2 bytes of file information per pixel contained in the image."
Wrong, Steve: what you meant to say is that there are 2 bytes per pixel, as 8 bits equals one byte. Proofread next time... and maybe stick with topics you understand! Lilley continued to tell his readers that,
"The second piece of information needed is the number of colors per pixel in the image. This is called the image 'depth.'"
Correct: and this means that a color image; which has pixels for red, green, and blue; uses 24 bits per pixel instead of eight¹. So, in fact, the formula for calculating the file size of an image depends on horizontal and vertical size in pixels plus pixel depth, almost as if you were calculating a volume. Since there are eight bits per byte and 1024 bytes per kilobyte, the file size of an image equals

# pixels horizontal * # pixels vertical * pixel depth
8 (bits per byte) * 1024 (bytes per kilobyte)

Steve's example is of an image that is 600 x 800 pixels, which is apparently B/W because he doesn't apply a pixel-depth multiplier. According to Lilley, this image will create a file of 960,000 bytes (just under 940 kb). In reality, the image file will be about 60 kb; only if it is 16-bit color (pixel depth = 16) would the answer be 940 kb. We verified that calculation at an online file-size calculator.
Steven's problem? Instead of dividing the number of bits by 8 (bits per byte) he multiplied it by 2 (number of bytes per pixel). It just goes to show you that a Dumbass of the Day can even screw up middle-school math. Not only that, Lilley completely ignored the value of pixel depth. In other words, his calculation would be even more wildly inaccurate for a color image.

¹ That's a generalization. In fact, pixel depth can range from one to (at this time) 48: it's not just eight.
copyright © 2019-2022 scmrak

MM - PHOTOGRAPHY

No comments: