Return to Digital Photography Articles

JPEG Compression, Quality and File Size

When trying to resave a digital photo, one is often faced with a decision as to what "quality settings" (level of compression) to use. The JPEG file format (more properly JFIF), allows one to select an appropriate trade-off between file size and image quality. It is important to understand that JPEG (and nearly all lossy file formats) are not suitable for intermediate editing because of the fact that repeated saves will generally diminish the working file's quality. In addition to the cumulative introduction of visual artefacts (error), repeated recompression also introduces destructive color changes. It is for these reasons that "lossless" file formats (such as TIFF, PSD, BMP, etc.) are better choices for intermediate processing. JPEG should only be used for storing the final image (ie. after editing) and possibly the initial capture.

How does JPEG compression work?

When a JPEG file is opened in an image editor, a large number of steps must be performed before the raw image (one RGB triplet per pixel) can be displayed or edited. It is easier to understand the process by looking at the reverse process — ie. what happens when one generates a JPEG file (ie. save) from the raw image data. In summary, the JPEG algorithm involves the following stages:

  • Color Space Conversion - The image first undergoes a color space conversion where it is remapped from RGB (Red Green Blue) triplets into YCbCr (Luminance, Chrominance Blue, Chrominance Red) triplets. This color space conversion assists the use of different quantization tables (one for luminance, the other for chrominance).
  • Segmentation into Blocks - The raw image data is chopped into 8x8 pixel blocks (these blocks are the Minimum Coded Unit). This means that the JPEG compression algorithm depends heavily on the position and alignment of these boundaries.
  • Discrete Cosine Transformation (DCT) - The image is transformed from a spatial domain representation to a frequency domain representation. This is perhaps the most confusing of all steps in the process and hardest to explain. Basically, the contents of the image are converted into a mathematical representation that is essentially a sum of wave (sinusoidal) patterns. For example, the binary sequence 101010 can be represented by a wave that repeats every two pixels. The sequence 1100110011 can be represented by a wave that repeats every four pixels. Similarly, the sequence 1001101011 can be represented by the sum of several simpler waves. Now imagine that this mapping to wave equations (known as the DCT basis functions) is done in both the X and Y directions.
  • Quantization - Given the resulting wave equations from the DCT step, they are sorted in order of low-frequency components (changes that occur over a longer distance across the image block) to high-frequency components (changes that might occur every pixel). Is it widely known that humans are more critical of errors in the low-frequency information than the high-frequency information. The JPEG algorithm discards many of these high-frequency (noise-like) details and preserves the slowly-changing image information. This is done by dividing all equation coefficients by a corresponding value in a quantization table and then rounding the result to the nearest integer. Components that either had a small coefficient or a large divisor in the quantiziation table will likely round to zero. The lower the quality setting, the greater the divisor, causing a greater chance of a zero result. On the converse, the highest quality setting would have quantization table values of all 1's, meaning the all of the original DCT data is preserved.

    An important point to realize here is that the quantization table used for this step differs between nearly all digital cameras and software packages. Since this is the most significant contributor of compression or recompression "error", one is almost always going to suffer image degradation in resaving from different compressors / sources. Camera manufacturers independently choose an arbitrary "image quality" name (or level) to assign to the 64-value quantization matrix that they devise, and so the names cannot be compared between makes or even models by the same manufacturer (i.e. Canon's "Fine" vs Nikon's "Fine").

    Please see my article on JPEG Quantization Tables for the actual tables used in the Canon, Nikon, Sigma, Photoshop CS2 and IrfanView digital photos.
  • Zigzag Scan - The resulting matrix after quantization will contain many zeros. The lower the quality setting, the more zeros will exist in the matrix. By re-ordering the matrix from the top-left corner into a 64-element vector in a zig-zag pattern, the matrix is essentially sorted from low-frequency components to high-frequency components. As the high-frequency components are the most likley to round to zero, one will typically end up with a run of zeros at the end of the 64-entry vector. This is important for the next step.
  • DPCM on DC component - On a block-by-block basis, the difference in the average value (across the entire block, the DC component) is encoded as a change from the previous block's value. This is known as Differential Pulse Code Modulation.
  • RLE on AC components - On the individual entries in the 64-element vector (the AC components), a Run Length Encoding stores each value along with the number of zeros preceeding it. As the 1x64 vector contains a lot of zeros, it is more efficient to save the non-zero values and then count the number of zeros between these non-zero values. The RLE stores a skip and a value, where skip is the number of zeros before this component, and the value is the next non-zero component.
  • Entropy Coding / Huffman Coding - A dictionary is created which represents commonly-used strings of values with a shorter code. More common strings / patterns use shorter codes (encoded in only a few bits), while less frequently used strings use longer codes. So long as the dictionary (Huffman table) is stored in the file, it is an easy matter to lookup the encoded bit string to recover the original values. See my JPEG Huffman Coding tutorial.

Examine your JPEG Files!

I have written a free Windows utility that examines and displays all of the details described above in your JPEG files.

Download JPEGsnoop here.

Where does the error come from?

By far the biggest contributor to the error (ie. file size savings) in the JPEG algorithm is the quantization step. This is also the step that allows tuning by the user. A user may choose to have a slightly smaller file while preserving much of the original (ie. high quality, or low compression ratio), or a much smaller file size with less accuracy in matching the original (ie. low quality, or high compression ratio). The tuning is simply done by selecting the scaling factor to use with the quantization table.

The act of rounding the coefficients to the nearest integer results in a loss of image information (or more specifically, adds to the error). With larger quality scaling factors (ie. low image quality setting or high numbers in the quantization table), the amount of information that is truncated or discarded becomes significant. It is this stage (when combined with the Run Length Encoding that compresses the zeros) that allows for significant compression capabilities.

There are other contributors to the compression error, such as the color space conversions, but the quantization step is the most important.

Please see my results in the JPEG Quantization Table article for a more accurate comparison between software packages and their quality settings.

JPEG Chroma Subsampling

In order to further improve JPEG compression rates, chroma subsampling is used to reduce the amount of image information to compress. Please refer to my article on Chroma Subsampling for more information on the 2x1 and 2x2 subsampling typically used in digital cameras and image editors such as Photoshop.

Breakthrough in JPEG compression?

Up until now, it has been widely assumed that the JPEG image compression is about as good as it gets as far as compression rates are concerned (unless one uses fractal compression, etc.). Compressing the JPEG files again by Zip or other generic compression programs typically offers no further improvement in size (and often does the reverse, increasing the size!).

As documented in a whitepaper written by the authors of StuffIt (Allume Systems, formerly Alladin Systems), they have apparently developed software that will further compress JPEG files by up to an additional 30%! Considering how many years the highly-compressed JPEG algorithm has been around, it is surprising to see any new developments that offer this degree of increased compression. Note that the "Stuffit Image Format" (SIF) uses lossless compression of the lossy-compressed original JPEG image. Therefore, there is no further image quality reduction in this Stuffit additional compression.

On Slashdot.org, there have been many theories as to how this additional compression could be achieved, but it seems that many feel that it must be through either replacement of the Huffman coding portion (and using arithmetic coding instead) or alternatives to the zig-zag reordering scan. It seems that the consensus is that SIF uses an implementation of arithmetic coding.

On first glance, this would seem to potentially revolutionize the photo industry. Imagine how this could affect online image hosts, or personal archiving needs. Saving 30% of the file size is a significant improvement. Unfortunately, a few significant problems are immediately apparent, possibly killing the adoption of this format:

  • Proprietary Standard - I cannot see this format taking off simply because a single company owns the format. Would you trust your entire photo collection to a single company's utility? The company can charge what it likes, has no guarantees about the company's future, etc. At least Adobe tried to do things right by releasing their DNG (Digital Negative format) specification to the open community, allowing many other developers to back the format. Allume / Stuffit sees this as a potential financial jackpot.
  • Processor Intensive / Slow - Unlike the methods used in the standard JPEG file compression scheme, the SIF method is apparently extremely slow. As tested by ACT (Archive Comparison Test website), a 1.8 GHz Pentium computer took nearly 8 seconds to compress or decompress a 3 megapixel file. While this is less of an issue for those wishing to archive photos to CD, for example, it is obvious that this would prevent the algorithm from ever being supported in most embedded applications (including within a digital camera).

Resaving and workflow

When resaving after making changes, I strive to preserve the quality of the original as much as possible and not lose additional detail to compression round-off error. Therefore, one should keep in mind a few suggestions about resaving:

OriginalSave as...Notes
TIFFTIFFIf the original was uncompressed, then it makes sense to resave it as uncompressed
BMPBMPIf the original was uncompressed, then it makes sense to resave it as uncompressed
JPG TIFF or BMP Best approach: Allows the best preservation of detail by saving in a lossless format. Unfortunately, this approach complicates things as most catalog programs don't handle the change of file type very well (as it changes the filename).
JPGJPG Alternate approach: While not as good as the previous approach that saved it in a lossless format, this can be adequate if the compression algorithm is the same (ie. same quantization tables & quality settings). If this is not possible, then resaving with a quality setting that is high enough (ie. striving for less compression than the original) might be the only choice.

If one intends to edit a JPEG file and resave it as a JPEG, the issue of recompression error should be given consideration. If a little additional error is not going to be of much concern (especially if it is nearly invisible), then resaving to match file size might be an adequate solution. If, however, the goal is to preserve the original image's detail as much as possible, then one has to take a closer look at the way the files are saved.

Option 1 - Resaving with no recompression error

All of the software applications that advertise "lossless" operations (such as lossless rotation) will resave the file with no additional recompression error. The only way that this can work is if the settings used in the compression algorithm match the settings of the original, identically. Any differences in the settings (more specifically, the quantization table and the quality setting / factor) will cause additional compression error.

Unfortunately, it is very difficult (as a user) to determine what these settings were, let alone have any control over them (besides the quality factor). Besides cjpeg, I haven't seen any other programs that actually allow you to configure the quantization tables yourself.

In an attempt to identify whether or not this option is even possible, I have compared the quantization tables of my digital camera to a couple imaging applications.

Fortunately, if one is resaving an image in the application that originally created the image (eg. saved an image in Photoshop, re-opened it, edited it and then resaved it in Photoshop), one can almost achieve this by simply resaving with the same quality settings as were used the previous time. As the quantization table is hardcoded, the user must ensure that the quality setting matches (not higher or lower than) the original. If one forgot what settings were used in the original, it is possible to make an educated guess by performing a couple test saves to compare by file size (across quality settings) to get a very rough idea.

Option 2 - Resaving with minimal recompression error

If one is resaving a photo with a different program than originally created the original (eg. Photoshop CS resaving an edited version of a photo direct from a digital camera), it is not possible to resave without some additional "loss" (recompression error) . The problem here is that the quantization tables and quality settings either are not known or they cannot be set. This is the most likely scenario for users editing their digital photos.

In this scenario, the goal is no longer "lossless resaving" but minimizing the additional recompression error that will be introduced. Making a very rough assumption, one can get an equivalent level of detail by resaving with settings that uses similar quantization tables. There are many reasons why this ends up being a rough assumption, but it should give a close approximation to the same level of detail.

Compression Quality and File Size

The following details the effect of JPEG quality on file size from several popular image editing programs. Unfortunately, each graphics program tends to use its own compression quality scale and quantization tables, and therefore, one can't simply transfer quality settings from one application to another.

As described in the section above, if one cannot guarantee lossless resaving (because of differences in the quantization tables), then it is worth looking at the quantization table comparison for a guideline.

Knowing what quality level is roughly equivalent to the original image helps in determining an appropriate quality level for resaving. Ideally, one doesn't want to resave at a lower quality level (and therefore lose image detail / quality), and on the other side, one shouldn't save at a higher quality setting as it simply wastes space and can in fact introduce extra recompression noise!

Digital Photo Source Characteristics

The source file for comparison purposes is a JPEG image shot with a Canon 10D digital SLR camera, recording a 6 megapixel image (3072x2048 pixels) at ISO 400 and super-fine quality. The source file size is 2280 KB.

Photoshop CS - JPEG Compression

For more detailed information, please see the article: Photoshop Save As vs Save for Web.

Notes:

  • Photoshop CS2 allows a range of quality settings in the Save As dialog box from 0..12 in integer increments.
  • Photoshop CS2 allows a range of quality settings in the Save For Web dialog box from 0..100 in integer increments.
  • A JPEG quality setting of around 11 achieved a similar file size to what was originally produced by the Canon 10D digital SLR camera (in super-fine mode).
  • Photoshop CS has three modes of saving JPEGs: Baseline, Baseline Optimized and Progressive. The difference in file size between these three modes (progressive was set to 3-scan) was in the order of about 20 KB for a 1 MB file. Of course this is dependent upon the content of the image, but it demonstrates the rough order of magnitude expected in the different modes.
  • An ICC profile was attached to the image, but it is simply the default sRGB, which is relatively insignificant (~ 4 KB).

Photoshop CS and Chroma Sub-sampling

Although it is not advertised, I have determined that Photoshop CS uses chroma subsampling only in certain quality level settings.

Photoshop does not allow the user to select whether or not Chroma Subsampling is used in the JPEG compression. Instead, 2x2 subsampling is used for all Save As at Quality 6 and below, while it is disabled (ie. 1x1 subsampling) for Save As at Quality 7 and higher. Similarly, it is used for all Save For Web operations at Quality 50 and below, while it is not used in Save For Web at Quality 51 and above.

Irfanview - JPEG Compression

Notes:

  • Irfanview allows a range of quality settings from 0..100 in integer increments.
  • It also allows one to select whether or not Chroma Subsampling is used in the JPEG compression.
  • With Chroma Subsampling disabled, it appears that a quality setting of 96 achieves comparable file size to the original.
  • With Chroma Subsampling enabled, a quality setting of around 98-99 creates a comparable file size to the original. However, it should be noted that the digital camera itself is using chroma subsampling (2x1), so that this figure is not particularly useful. In other words, if the original source used chroma subsampling, then there is no point in resaving it without chroma subsampling — the additional CbCr color information is already gone. In the example image I have used for the above analysis, chroma subsampling offered approximately 25% savings in file size over the same JPEG compression without.

Miscellaneous Topics

Beware of Photoshop Save For Web

Although Photoshop's Save for the Web dialog seems great as it lets one interactively set the image dimension, palette depth and compression quality, it performs one potentially disastrous effect: the removal of EXIF metadata!

You will find that the file sizes after using "Save for the Web" will be smaller than if you had simply chosen "Save As..." with equal compression settings. The difference is in the lost image metadata (time / date / aperture / shutter speed / etc).

The only time that it is worth using "Save for the Web" is when one is creating web graphics (where you are optimizing for speed) or deliberately wants to eliminate the metadata (eg. for photo galleries, privacy, etc.).

 


Reader's Comments:

Please leave your comments or suggestions below!
2007-11-04maadjordan
 please refer to Packjpg as a free alternative to stuffit with much improved support .. it supports CMYK jpegs, ..site here
www.elektronik.htw-aalen.de/packJPG
 Thanks for the pointer. I am sure many people have been hesitant to use the arithmetic coding implementation in Stuffit because it was essentially a closed, commercial format. It is good to see an alternative.
2007-09-29James
 Hi,
I have been adjusting some old JPEG photos in Photoshop taken with a 8.2mp camera, then resaving as JPEG. When I choose the highest quality the file size defaults to just 56kbs. Is this really the optimum size for my photo or should I increase the file size to ensure I don't lose extra detail ? Also, I have recently started shooting in RAW. Is the best thing to save the images as TIFF and only convert to JPEG if I am adding them to websites etc ?
 Are you resizing your images before saving?

If not, 56KB is certainly not a realistic file size for an 8 megapixel image! The compression ratio would be far too high. If you are resizing the image before saving (which I presume you may be doing), then the 56KB may be fair, for an image in the order of ~ 800x533 pixels. If your images are much larger than this, then you may be sacrificing quality.

However, one can't judge quality from file size -- the size is dependent upon both the compression quality (you say that you're saving at highest quality), and the image content. Since every image has different "content", some images will compress much more easily than others. So, I cannot give you any real guidelines based on file size.

If you are shooting RAW and want to modify these images and preserve these mods for later re-edits or re-purposing for the web/print, etc. then it is most appropriate to save them as TIFFs. Once you are sure of your final output, you can save as JPEG. Re-editing a saved JPEG (from an image editor) will increase the cumulative "error", which may degrade your image after an iteration or two.
2007-08-24Nermin Kura
 Hello,

I am trying to resize a raw image inorder to enter it for a show. I am being asked to reduce the length of the highest side to 800 pixels and to lower the resolution to 72 ppi and 8 bit jpeg. Then they ask me to reduce the compression quality to 8. What does that mean and where does one find that in the "save for web" settings? Where is the button or dial to do that? I would be most grateful for your help.

cheers,
Nermin
 Hi Nermin -- The easiest way to accomplish this is to do the following:
  • Image->Mode->8 bits/channel
  • Image->Image Size...
    If either Width or Height is greater than 800 pixels, then type 800 into the field of the larger of the two fields. Make sure "Constrain Proportions" is checked. Also check Resample Image, and preferably select "Bicubic Sharper".
  • File->Save As...
    Here, you'll want to select JPEG and then an Image Quality of 8.
Instead of using File->Save As, you can use File->Save for Web, but the compression quality range is not equivalent (the range is also different, it goes from 1-100 instead of 0-12). As shown on my compression quality page, Save As Quality 8 is roughly equivalent to Save for Web Quality 60.
2007-08-08Julio Garcia
 I wish to know, if a relationship between Quality level and Compression Rate exists. I mean, if a JPEG image is compressed at 85, the result compression rate is X bpp.

Thanks.
 Unfortunately, no. The problem is that Compression Rate is dependent upon both the "quality level" (more specifically, the quantization matrix) as well as the image content! At the same quality level, image content that is easy to compress (flat color, little detail) will result in a much lower bpp (bits per pixel) than a detailed image with the same compression quality settings. This is why high-ISO noise leads to lower compression efficiency (and larger file sizes) in photos taken by a digital camera with the same quality setting.
 
2007-05-15Carolyn
 I've bought a compact Nikon S50c to carry around with me instead of my bigger cameras. It offers different resolutions saved to 1:8 or 7MP in 1:4 compression. This way of describing the jpeg compression is new to me (though more descriptive), as I've always had cameras that used "Fine," or software that was either equally non-descriptive or used "90% quality" or something to that effect. How does one compare all these different ways of describing jpegs? There doesn't seem to be any way to set my S50c to anything similar to the 5MP Fine that I get on my Nikon 8700.
 There are a few possibilities here. I see that the S50 provides a High and a Normal image mode. The names given to these settings are really arbitrary (so the High on this camera could potentially be analogous to the Fine on another camera) -- however, Nikon also chose to publish an approximate compression ratio.

According to the product brochure, High has a compression ratio of approximately 1:4 and Normal is approximately 1:8. If these ratios were actually guaranteed by the camera, this would mean that the file sizes per photo would theoretically be:

Image ModeResolutionCompression RatioTheoretical File Size
High3072x2304 (7.1 MP)1:45308 KB
Normal3072x2304 (7.1 MP)1:82654 KB
Normal2592x1944 (5.0 MP)1:81890 KB
Normal2048x1536 (3.1 MP)1:81180 KB
16:93072x1728 (5.3 MP)1:81991 KB

Normally, camera manufacturers don't publish the compression ratio value because it is generally very much dependent upon the image content -- assuming the quantization table (JPEG quality setting) remains constant for all photos. In some recent cameras, auto compression or variable JPEG quantization is being used in an effort to make the compression ratio constant or the overall file size constant. As I can't find any full-resolution unretouched photos from the Nikon S50/S50c, I cannot confirm that the camera is in fact doing this. Feel free to email me 2 or 3 photos from your camera (in High mode) and I can give you a more definitive answer.

In all likelihood, the camera is probably using the traditional means of selecting a JPEG quality setting (fixed quantization table) and they are mentioning the 1:8 and 1:4 compression ratios as a very rough estimate. If your file sizes deviate greatly from the sizes shown in the table above, then this assumption is likely correct. It is pretty misleading to publish a approximate compression ratio as there are so many factors that would normally influence the overall ratio (ISO setting, amount of noise, complexity of the photo / level of detail, focus, etc.).

To answer your original question: how does one compare these settings -- in the most general case, one can compare the image quality factors from various cameras, but this is not a particularly easy metric to understand. From the most simplistic of viewpoints, simply treat "High" as somewhat equivalent to "Fine" from your other camera, with some differences that may not be very noticeable.

But, if the camera is using the variable compression mechanism (which I can confirm if you point me to some high-resolution samples), then we have a much better way of comparing the quality settings.
2007-03-16Sanjay
 My new Nokia 6300 mobile has a 2 MP Camera but the file size is only 430kb (approx.) and my old Olympus 2 MP digital camera file sizes are 800kb to 1Mb. I also observe that the 6300 images far inferior even after setting Image quality to 'high'. Is it happening due to built in higher JPEG compression of 6300? Is there anything I can do to see better images from 6300.
 Possibly. First, it's important that one doesn't completely rely on comparison of file size because if a digital camera (camera phone) were to take very noisy pictures (poor quality), it may generate larger files than the higher quality, less noisy ones.

That said, the quantization tables that are used to specify the quality of the phone's JPEG compression are often stored within the firmware of the cell phone. Sometimes you are able to modify these quantization tables in the firmware, allowing for better images. For example, on this site, a programmer has hacked the Motorola E398 phone to use the quantization tables provided on my site, thereby improving the picture quality.

In a similar way, I have also been working on a hack to the Canon scanner drivers so that they produce better JPEG images during auto-scan modes.
2006-11-30Doug Pardee
 This page says under "Photoshop CS and Chroma Sub-sampling", "Instead, 2x1 subsampling is used for all Save As at Quality 6 and below..."

Your later articles say "2x2" subsampling for Photoshop. Is this something that should be corrected on this page, or is it a difference between CS and CS2?

Also, toward the beginning under "How does JPEG compression work?", the first paragraph discussing "Quantization" seems to be unfinished.
 It should have read 2x2 -- thanks! As far as I know Photoshop has never used 2x1 chroma subsampling, nor can one configure it to. Therefore, the JPEG compression used by Photoshop's image resaving will generally never match that used natively by most digital cameras.

As for the quantization section, I have updated the page to provide additional description. Thanks for noticing this, Doug!
2006-11-18Akim
 Could you explane more about:
Discrete Cosine Transformation
DPCM on DC component
RLE on AC components

Thx
 The best detailed reference for all of these is the JPEG Standard itself: ITU-T81 JPEG PDF. In it you will find the steps required to implement the full algorithm. Good luck!
2006-09-14carlotta
 help ! i have shot in TIFF and need to deliver in JPEG however on converting i seem to lose about 90% in size. i edit in photoshop and then save as JPEG. even though i select highest quality of 12 the MB size jumps down from around 20MB to about 2.5MB. how can i convert my TIFFs to JPEGS without losing so much data ?? thank you ..
 If you are shooting in TIFF, you are avoiding the lossless compression stage in the camera. But TIFF "lossless" compression is only about 3:1. When you resave it as a JPEG, you are going to throw away some detail, but this is generally imperceptable. Don't be concerned about the reduction in file size -- JPEG compression is well-tuned to perception and you'll have a hard time distinguishing the high-quality JPEG from the original TIFF. Saving with Photoshop Quality 11 or 12 may be appropriate as you will also avoid any chroma subsampling in the process. If you are really concerned about image quality, save it at Quality 12, as it appears that your resulting file sizes are quite reasonable.
 
2006-09-05Matt Webster
 Thanks for your help, I've managed to get something working which i think is close enough for what i need it for and I've set quite a high margin of error in the rounding.

Thanks again
2006-09-04Matt Webster
 Hi there

I trying to derive a formula that will give an approx. file size for a JPEG image depending on the megapixels of the camera it was taken with. Any suggestions?
 This won't be easy. The amount of file compression you get with the JPEG format is highly dependent upon the content, camera settings (quality level) and model of camera in addition to the resolution in megapixels. The JPEG2000 format (which has not caught on for digital camera use) would indeed provide a known relationship between camera settings and file size. ISO settings (and the associated noise) can have a huge impact on file size (increasing ISO can easily double file size).

So the best bet is to do what memory card manufacturers have been doing for ages when the indicate this 512MB card can store X photos (5 megapixels). In order to do this, a really rough assumption is made about the the contributing factors to the end result compression levels. For example, in a day's shoot with a 6-megapixel Canon dSLR (such as the Digital Rebel), I see a range from 1.5MB - 4.7MB for a 3072x2048 image. The 1.5MB images were for flowers with long natural gradients of color, while the 4.7MB images were of a highly-detailed mural on stucco, with lots of texture.

That being said, Lexar has an example capacity chart that attempts to place some rough averages from various-sized digital photos. Boiling down their numbers, it seems that their suggested compressed file size per megapixel is non-linear with respect to the resolution!! Odd, but this may have been derived from a sampling of different digicams, not synthetic extrapolations. The rough starting point is a JPEG compression ratio of ~ 6.5:1. Have a look below (calculations were based on original Lexar data):

Photo
Resolution
128MB Card
Capacity
MB/PhotoMB/MegapixelJPEG
Compression
Ratio
2 Megapixel134 photos0.962.16.3:1
3 Megapixel120 photos1.072.88.4:1
5 Megapixel48 photos2.671.95.6:1
8 Megapixel36 photos3.562.36.8:1
10 Megapixel26 photos4.922.06.1:1
Capacity : JPEG Compression Ratio
2006-08-17Johannes
 Hello Calvin,

do you know a tool which reports the chroma-subsampling of a jpeg-file?

Thanks
Johannes
 [UPDATE 2006-09-08]: I have now written a simple Windows application that can do this for you. Please download JPEGsnoop. Hope that helps!

I am not aware of any non-commercial Windows applications that report the chroma-subsampling of an image. However, it isn't that hard to extract from a JPEG file if you have a hex editor and the reference to the ITU-T.81 Specification. There are various JPEG file format marker dumping command-line tools out there (most with source available), and almost all are called jpegdump. One of these does in fact report the sampling frequencies for each component (1 luminance, 2 chrominance).

In the report, look for the Start of Frame (SOF JFIF marker). In a Canon 10d JPEG file, it reported the following:
offset $2a9e SOF0 (baseline DCT Huffman) (length 17)
  sample precision 8
  width 2048, height 3072  components 3
    id 1 horizontal sampling 1, vertical sampling 2, quantization table 0
    id 2 horizontal sampling 1, vertical sampling 1, quantization table 1
    id 3 horizontal sampling 1, vertical sampling 1, quantization table 1

In the above, quantization table 0 refers to the luminance, while quantization table 1 refers to the two chrominance tables. In the above example, you have to first find the maximum sampling factor for the horizontal and vertical directions. In the above, Hmax=1, Vmax=2. Then, one looks at each of the chrominance components (id 2 and id 3). For the chrominance, we see that it reports a Horizontal Sampling of 1 and a Vertical Sampling of 1. To find out the subsampling for each component, divide the HMax by the Horizontal sampling, and VMax by the Vertical sampling.

This leads to a sub-sampling of 1 in the horizontal direction and a sub-sampling of 2 in the vertical direction. At first this looks wrong, but then you'll realize that this image has been rotated (portrait orientation), probably by Downloader Pro when imported. So, you can infer that the original JPEG image from the Canon 10d has a chroma subsampling of 2 in the horizontal direction and no subsampling in the vertical direction..

I usually use a Hex Editor to get these quantities (as these jpegdump programs are often flaky). For the SOF JFIF marker, I search for FFC0. Then, I extract each component and field parameters according to the ITU-T standard mentioned above.

Hope this helps!
2006-08-10Joan
 My camera takes photos as JPEGS. Ater tranferring the images to my compute, if I open a photo and then close it again repeatedly, without making any changes, the file size remains the same. Have I, nonetheless, degraded the quality of the image by doing so?
 Not at all :) The only way that you could ever degrade the quality of the images is if you re-save after opening them. Open as many times as you like! Even if you accidentally resaved an image, the accompanying degradation in quality is often quite minimal, to the extent where the average person would have an extremely hard time identifying the difference.
2006-03-27rajbala
 sir,
The above info.. is very useful for "digital video processing" project..But i want image comparision in the form of "whether your image is able to compress in the ratio of 1:2,1:4,1:6 and so on"
thanking u sir
your's
rajbala
 With the basic JPEG algorithm, one cannot specify ahead of time what compression ratio / factor you want -- the quality factor is linked to overall compression ratio depending on image content. The newer (but not mainstream) JPEG2000 format does provide this ability, though.
2006-03-16Benj
 We have seen a few people mention how the "Save for Web" Feature in Photoshop loses the Meta Data in the resulting file...SO WHY DO WE PUT UP WITH IT?

Everyone should go to the Adobe.com Website and click on the "contact us" link at the top of the page. The 3rd option in the "Give Feedback" Section is "Product Feature Request." Click on this, and then explain to them why they need to fix this so more forums and discussions can be spent issues who's sollutions aren't so obvious.

ADOBE!!!!! PLEASE FIX THIS NOW!!!! thanks! ;)
 I must admit that Photoshop doesn't make obvious the distinction between Save As and Save For The Web with respect to metadata. I think in the most general case (excluding photographers who are trying to maintain web galleries with metadata), people are more interested in reducing file size for the web and hence the automatic removal. However, it would seem like a good feature to add the ability to prevent the metadata discard.
2005-12-08ben
 Photoshop's "Save for web" feature removes something else from the file that takes up at least as much space as the entire metadata table: the image preview.

When you "save" or "save as" in Photoshop, you get a fairly large "preview" image attached to the image file, which OS X, for example, reads. Incidentally, the Canon JPG creation process that happens on-camera also creates a preview frame and attaches it to the image. In large files it is an irrelevant amount of information, but if you have a web page with 50 small GIF or JPG files to load, the difference between 4kb and 24kb is pretty significant, and that's about how much adding the "preview" info seems to add to the files I work with.
 You're right... The JFIF format allows for an extension which includes a compressed thumbnail image in addition to the main image. As this thumbnail can also be 24-bits per pixel, it can certainly occupy a moderate amount of space. This extra is only really an issue for web-targeted images. Depending on the quality and size, it is conceivable that 20kb could be added. Thanks!
2005-08-15Thomas
 

I use XnView to view & save my images. It would be interesting to see how this program perfomes in comparison to IrfanView.

Excellent and interesting & deep article(s)! :) Thomas

 

Thanks for the pointer... I've added it to the list.

 


Leave a comment or suggestion for this page:

(Never Shown - Optional, if you want a reply)
 

I will be out of the country for several months (in India), so comments will be held and only posted infrequently. Thanks!

13 users online