The largest size of a 640×480 JPEG

imagesjpegmemory-card

I'm creating a data storage device that takes a certain number of pictures of the night sky over a couple of hours, and the pictures will be downloaded right after they are all taken. The memory card must be able to store all of the pictures at once.

The JPEGs that will be taken are 640×480 pixels, and it is essential that there is enough room on the memory card for all 100 of them. So what is the largest size of a 640×480 JPEG?

I have taken some test pictures to figure this out:

#1#2#3

  • The file size of the "stackoverflow" image is 73,774 bytes.
  • The file size of the white image is only 36,607 bytes.
  • But the file size for the checkered photo clocks in at 149,339 bytes.

I am assuming that the file size increases with complexity.

How can I build enough room on the memory card to fit 100 640×480 JPEGS, without knowing how complicated and what size they will be? I don't want to waste extra space as I may be making many of these capture devices.

Best Answer

Here I suggest an upper bound for JPEG file sizes. See Ilmari Karonen's answer for a discussion of more typical jpeg sizes.

The pixel storage space for a 640X480 32-bit bitmap image can be calculated like so (based on this answer, but corrected based on Ignacio Vazquez-Abrams' comment and this answer):

Assuming that no compression has been applied to the file, there are 307,200 pixels, which is a 0.3MP. Handy look up table

If each pixel contains 32 bits of information, then

  1. 307,200 * 32 = 9,830,400 bits of information
  2. Divide by the 8 bits to become a byte value
  3. 9,830,400 / 8 = 1228800 bytes (Or 1.17 Mb)

This is the size of an uncompressed bitmap, and as such should be an upper bound for jpeg file size (In reality, because the JPEG format uses compression, your images should be much smaller, especially given that you're taking pictures of the night sky, which I imagine contains a lot of black. Note that the largest example image in your question is only 0.14 MB).

With regard to your specific issue however, even using that upper bound, 100 images is only 117 MB, and it's been a long time since I've seen a memory card as small as 128 MB. I suspect any currently available memory card will have enough capacity to meet your needs.

Apparently the issue of maximum jpeg file size is subject to some debate. This Stack Overflow answer suggests a theoretical maximum size of 20.25 bytes per pixel, or 5.9 MB in your case, but producing an image of that size requires deliberate misuse of the jpeg format's compression scheme, so it's extremely unlikely that you'd ever see such a thing produced by a camera.