Basic understanding of "JPEG Quality"?
Moderators: XnTriq, helmut, xnview
-
- XnThusiast
- Posts: 1347
- Joined: Thu Nov 24, 2005 3:07 pm
- Location: CH
Basic understanding of "JPEG Quality"?
Do I understand it right: "The quality level is always relative to the current setting"
When I save a JPG file with "quality 85%" three times, it results in a final quality of "0.85*0.85*0.85 = 61%".
When I save a JPG file with "quality 100%", it results in an unmodified quality.
Right?
Best wishes from fine snow-fall!
When I save a JPG file with "quality 85%" three times, it results in a final quality of "0.85*0.85*0.85 = 61%".
When I save a JPG file with "quality 100%", it results in an unmodified quality.
Right?
Best wishes from fine snow-fall!
XnViewMP <Current version> German, XnConvert <Current version>, Win 10
-
- XnThusiast
- Posts: 4132
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Basic understanding of "JPEG Quality"?
I am confident that is not accurate...
That is either correct, or certainly correct for all practical purposes.When I save a JPG file with "quality 100%", it results in an unmodified quality.
JPEQ compression is complex, and I certainly have only a limited understanding: there is a detailed description on the Wikipedia JPEG page if you want more detail.
The potential loss of quality when resaving a JPEG derives from use of a quanization table in the recompression of the file, quanization tables having various possible sizes. The JPEG saving option 'use estimated quality (when possible)' is designed to minimise any loss by, I think, using the table size previously used. XnTriq is, of course, the expert on all these matters...
To further complicate matters, 'quality' scales used in software products are not standardised.
Best wishes from Freistaat England!Best wishes from fine snow-fall!
-
- XnThusiast
- Posts: 1347
- Joined: Thu Nov 24, 2005 3:07 pm
- Location: CH
Re: Basic understanding of "JPEG Quality"?
The idea behind it is that I use "nconvert.exe" to add text in multiple lines. Because (at the moment) there is no multiline-feature, I have to repeat "write line - save jpg - write line - save ..."
And I want to avoid the loss of quality.
And I want to avoid the loss of quality.
XnViewMP <Current version> German, XnConvert <Current version>, Win 10
-
- XnThusiast
- Posts: 4132
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Basic understanding of "JPEG Quality"?
I think in most situations saving a JPEG multiple times is much less of an issue than many people think.
I suggest that you save at the default quality of 85, or higher if you wish using the -q option, and possibly compare the output of successively saved versions to see if you can actually see any difference in quality. If file size is an issue you could if necessary save at 100, and then make the final save at a lower value.
Ideally you would probably save using a 'use estimated quality' option, but I don't see that option in a quick look at the NConvert 7.39 Help file, and I am not sure if it has been requested, if not it would be a useful addition...
Two general observations:
In my experience images with large pixel dimensions, such as scans made at high resolution, can be compressed using quite low quality values with little or no visible loss of quality.
And the JPEG format is in principle unsuited to images containing sharp edges such as lines and text characters, nonetheless for colour and grayscale images it is often the best option overall when filesize is an issue. Images that are 1-bit black and white, however, are generally much better saved as TIFFs using 'Fax' CCITT G4 compression, resulting in lossless images with much smaller filesizes.
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
foxyshadis is our resident expert b/c she understands the math behind it
Forum references regarding the JFIF/JPEG file format:
- JPEG compression as lossless as possible
- Standard Values for JPG-Compression and EXIF/IPTC settings
- a picture problem for help
- "export" vs. "save as / writing options"
- Lossless JPEG transformations
- Save JPG At 'Original' Quality
- JPEG Lossless does not support non-rgb colorspaces
- progressive to baseline jpeg
- Options->Read/Write->JPG: Use estimated Quality
- Diverging display of JPEG images
- XnView uses same JPEG encoder as GIMP ?
- JPEGsnoop — JPEG File Decoding Utility
- What exactly does "subsampling factor" do?
- Advanced JPEG I/O
- Differences in nconvert&xnview jpeg compression
- More explanations for simple users
- Lossless JPEG cropping á la JPEGCROPS
- Lossless Transformation
- Rotation sans perte et message d'avertissement sans raison
- JPEG Lossless Join
- JPEG properties
- Adjust-Automatic Levels / filesize
- JPEG Quality Settings
- Free JPG reduction service
- Newbie somewhat confused, needing some basic pointers
- JPEG Lossless question. Why is the file size smaller?
- Sample of diff. images for user-training
- Suggestion - JPEG compression quality info
- Arithmetic decoding disabled in libjpeg-turbo
- Should "DCT Method" be fast or slow?
- Show visual difference between original and encoded images
- JPEG lossless transformation format and arithmetic coding
- Cant view lossless jpg?
- Estimated quality for JPEG export
- Unable to change DPI of JPG image
- Saving a lossless JPEG
- Extended properties for JPEG files
- Question to various rotate
- Cleaning Metadata Without Altering Image
- Convert JPEG from 72 dpi to 300 dpi
- Display JPEG quality / compression level in info box
- Clean Metadata re-encodes JPEGs
- Can someone recommend settings?
- Automate operation "Join of images"
- Is there a way to view the quality of jpg images?
- Guetzli JPEG Encoder does not work
- Cleaning IPTC metadata erases Photoshop JPEG markers (APP13)
- How to keep photo quality after batch resizing?
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
Wikipedia:
https://en.wikipedia.org/wiki/JPEG#JPEG_codec_example wrote:
Although a JPEG file can be encoded in various ways, most commonly it is done with JFIF encoding. The encoding process consists of several steps:
The decoding process reverses these steps, except the quantization because it is irreversible. In the remainder of this section, the encoding and decoding processes are described in more detail.
- The representation of the colors in the image is converted to Y' C_B C_R, consisting of one luma component (Y'), representing brightness, and two chroma components, (C_B and C_R), representing color. This step is sometimes skipped.
- The resolution of the chroma data is reduced, usually by a factor of 2 or 3. This reflects the fact that the eye is less sensitive to fine color details than to fine brightness details.
- The image is split into blocks of 8×8 pixels, and for each block, each of the Y, C_B, and C_R data undergoes the discrete cosine transform (DCT). A DCT is similar to a Fourier transform in the sense that it produces a kind of spatial frequency spectrum.
- The amplitudes of the frequency components are quantized. Human vision is much more sensitive to small variations in color or brightness over large areas than to the strength of high-frequency brightness variations. Therefore, the magnitudes of the high-frequency components are stored with a lower accuracy than the low-frequency components. The quality setting of the encoder (for example 50 or 95 on a scale of 0–100 in the Independent JPEG Group's library) affects to what extent the resolution of each frequency component is reduced. If an excessively low quality setting is used, the high-frequency components are discarded altogether.
- The resulting data for all 8×8 blocks is further compressed with a lossless algorithm, a variant of Huffman encoding.
- Joint Photographic Experts Group
- libjpeg
- JPEG File Interchange Format (JFIF)
- JPEG
- Lossless JPEG (JPEG-LS, JPEG XT, JPEG 2000)
- YCbCr
- Chroma subsampling
- Transform coding
- Discrete cosine transform
- Entropy encoding
- Huffman coding
- Quantization (image processing)
- Color quantization
- Image compression
- Lossy compression
- Compression artifact
- Ringing artifacts → JPEG
- Colour banding
- Generation loss
- Image quality
- Guetzli
-
- XnThusiast
- Posts: 4132
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Basic understanding of "JPEG Quality"?
I hope Peter2 is following this thread closely after he asked for advice!
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
Useful software for analyzing and editing JPEGs:
- Independent JPEG Group
- jpg*exe.zip = cjpeg/djpeg + rdjpgcom/wrjpgcom + jpegtran
“Binaries for Win32 compatible systems of sample applications of the Independent JPEG Group's free JPEG software” - Jpegcrop
“The Jpegcrop Windows Application was initially developed to provide a convenient interactive user interface for the new jpegtran -crop feature. It has now developed to a nearly complete user interface replacement for jpegtran, and furthermore for demonstration of the new djpeg and jpegtran -scale features.” - JPEG Online Laboratory
“This tool can be regarded as Web-based Front End to the jpegtran utility for lossless JPEG transcoding from the Independent JPEG Group. This means that all transformations performed by this tool retain the original image contents, with no further quality loss! Only reversible image transformations are performed.”
- jpg*exe.zip = cjpeg/djpeg + rdjpgcom/wrjpgcom + jpegtran
- Toke Eskildsen
- JPEGCrops
“JPEGCrops is a Windows program, created for preparation of a batch of images for printing. It provides lossless cropping with fixed aspects using jpegtran.”
- JPEGCrops
- AnnyStudio
- JPEG Lossless Rotator
“Free and simple software for turning digital photos to the correct orientation”
- JPEG Lossless Rotator
- BetterJPEG
- BetterJPEG Editor
“BetterJPEG is a JPEG editor specifically designed to avoid recompression loss when editing and resaving JPEG images. BetterJPEG takes advantage of the fact that JPEG images consist of a number of small independent blocks and does not recompress blocks that don't have to be changed.” - BetterJPEG Plug-in for Photoshop
- BetterJPEG Editor
- RealWorld Graphics
- RealWorld Photo Editor
“Retouch photographs and batch process images in an easy-to-use editor. Perform lossless retouching, watermarking and other operations on .jpg images.”
- RealWorld Photo Editor
- Calvin Hass
- JPEGsnoop
“JPEGsnoop is a free Windows application that examines and decodes the inner details of JPEG and MotionJPEG AVI files. It can also be used to analyze the source of an image to test its authenticity.”
- JPEGsnoop
- Stuffware
- Photo Studio
“Photo Studio is a useful tool for examining and manipulating the contents of additional data stored along with your images, supporting a wide range of formats from EXIF/DCF and CIFF (as saved by many digital cameras) through JFIF to the often used Photoshop extensions.”
- Photo Studio
- MediaChance
- JpgQ – JPEG Quality Estimator
“What is the quality of JPEG already saved on disk? This small free software applet will estimate the quality of the JPG image. This is also the quality you should use if you load this image again in the photo editor (such Photobrush) and then re-save as JPG once again.”
- JpgQ – JPEG Quality Estimator
- Colosseum Builders
- JPEGDUMP
“This application dumps the contents of JPEG blocks in a JFIF file.“
- JPEGDUMP
- Lucian Sabo: RIOT – Radical Image Optimization Tool
- Stand-alone application
“A free program designed to efficiently optimize images for the Web” - XnView AddOn
“Pierre-e Gougelet, the author of XnView, created an addon to use RIOT in it’s well known viewer.
Now XnView users have RIOT integrated into their favorite viewer to be able to easily optimize pictures using RIOT.” - DLL version
“The RIOT addon for XnView is accesible after installing by selecting Filter->RIOT if an image is viewed or Tools->Plugin->RIOT in the XnView file browser.”
- Stand-alone application
- Ulead Systems
- SmartSaver
“Ulead SmartSaver Pro takes almost any image file format – including GIF animations – and optimizes it for the Web. Simple one-click commands, side-by-side before and after previews, customizable presets, and industry-leading optimization routines make SmartSaver Pro the best optimizer on the Internet.”
- SmartSaver
- XAT
- Image Optimizer
“Image Optimizer is designed to to prepare the best possible JPEG, GIF and PNG image files for the web. File size reductions of up to 50% or often much more are possible, which can considerably decrease web page download times, reduce server load, reduce bandwidth charges and save on disk space.”
- Image Optimizer
- Phil Harvey
- ExifTool
“A command-line application and Perl library for reading and writing EXIF, GPS, IPTC, XMP, makernotes and other meta information in image, audio and video files.” - ExifToolGUI for Windows
- ExifTool
- Jens Duttke
- PhotoME
“PhotoME is a powerful tool to show and edit the meta data of image files. Thanks to the well organised layout and intuitive handling, it's possible to analyse and modify Exif and IPTC-NAA data as well as analyse ICC profiles – and it's completely FREE!”
- PhotoME
- Matthias Wandel
- jhead – Exif Jpeg header manipulation tool
“Jhead is a command line driven program for manipulating the non-image parts of Exif flavour JPEG files that most digital cameras produce.”
- jhead – Exif Jpeg header manipulation tool
-
- XnThusiast
- Posts: 1347
- Joined: Thu Nov 24, 2005 3:07 pm
- Location: CH
Re: Basic understanding of "JPEG Quality"?
Yes, of course I'm following the thread.
I'm always hoping for a "yes/no" answer and I'm always afraid when XnTriq starts his IKM (incredible knowledge machine).
XnViewMP <Current version> German, XnConvert <Current version>, Win 10
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
I'd love to give you a straightforward answer, but when it comes to JPEG, there's no one-size-fits-all solution. It's the nature of the beast
Initiating yet another BLS (binge-linking spree)…
http://www.impulseadventure.com/photo/jpeg-quality.html wrote:Important note about Quality Factors
It is extremely important that the reader understand that compression quality cannot truly be represented by a single value. JPEG compression quality is actually defined by a pair of quantization tables (each with an array of 64 values). Trying to make a comparison between a pair of matrices is not at all straightforward (or always possible).
So, then why are “quality” numbers listed for each camera/software source? Many programs encode their JPEG images using quantization tables that are generated by scaling the coefficients in a “standard” table that is provided in the ITU-T specification.
The IJG group has proposed a method of scaling these coefficients according to a “quality factor” scale. This is NOT a percentage! It is merely a number from 1-100 representing the scaling factor used in generating the table. A quality factor of 100 does not mean Lossless compression! Instead, it generally represents the quality factor that will generate the highest quality compressed image with the provided scaling algorithm.
That said, many software programs and some digicams are indeed using scaled versions of this standard table. If we know that a given program has used the IJG scaling method, then we can indeed make a comparison, because all numbers in the matrices will move according to the algorithm in a similar manner.
So, what about other digicams / software editors that didn't use the IJG scaling method? People always love to make comparisons, and comparing multiple 64-element matrices is not intuitive to the average person. Therefore, as an incredibly rough approximation, a calculation has been made for each source to derive the closest / approximate IJG quality factor for a given table. If the quantization tables follow the standard trend of limited compression in the low-frequency components rising to moderate compression in the high-frequency components, then the approximate quality factor may indeed give one an idea as to how the overall quality may appear.
https://www.impulseadventure.com/photo/jpeg-snoop-uses.html wrote:Identifying JPEG Quality
One of the more interesting details about a JPEG image is how the image quality is defined. The quality is defined in what is known as a quantization table, which is a series of 64 values representing different frequency components in the image. JPEGsnoop displays these tables under the marker section DQT.
Many programs use their own tables, while some base it on the example provided in the JPEG Standard Annex K. JPEGsnoop attempts to calculate an image quality rating that is based on the standard tables (compatible with cjpeg, djpeg and other tools). To help one identify whether or not the quantization table was derived from the example ones in the Annex, JPEGsnoop calculates the ratio between the Annex table and the file's table, after the heading: AnnexRatio. If all the values nearly the same, then it implies that the quantization table is simply a scaled version of the Annex table.
If the quantization tables are indeed based on the Annex table, then the quality factor (Approx quality factor) that is displayed should be accurate.
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
This is a common misconception. I had to learn the hard way that re-encoding a JPEG is always lossy.When I save a JPG file with "quality 100%", it results in an unmodified quality.
XnView's “JPEG functions are based in part on the work of the Independent JPEG group” (Info → About…). The IJG is maintaining and publishing libjpeg which comes with a utility called jpegtran capable of “lossless JPEG trans-coding” (vs. en-coding). With the exception of -wipe*, Pierre has inplemented these function into his software.https://www.lifewire.com/jpeg-myths-and-facts-1701548 wrote:A Quality Setting of 100 Does Not Degrade an Image at All: False
Saving an image to JPEG format always introduces some loss in quality, although the loss at a quality setting of 100 is barely detectable by the average eye. In addition, using a quality setting of 100 compared to a quality setting of 90 to 95 or so will result in a considerably higher file size relative to the degree of image loss. If your software doesn't provide a preview, try saving several copies of an image at 90, 95, and 100 quality and compare file size with image quality. Chances are there will be no distinguishable difference between the 90 and 100 images, but the difference in size could be significant. Subtle color shifting is one effect of JPEG compression – even at high-quality settings – so JPEG should be avoided in situations where precise color matching is important.
XnView Classic:
- Edit → Metadata → Clean… → Optimize (Huffman table)
- Tools → JPEG lossless tranformations → Rotate 90° left (cmd_JPEGRotation270)
- Tools → JPEG lossless tranformations → Rotate 90° right (cmd_JPEGRotation90)
- Tools → JPEG lossless tranformations → Rotate 180° (cmd_JPEGRotation180)
- Tools → JPEG lossless tranformations → Flip Vertical (cmd_JPEGVerticalFlip)
- Tools → JPEG lossless tranformations → Flip Horizontal (cmd_JPEGHorizontalFlip)
- Tools → JPEG lossless tranformations → Crop
A complementary lossless-wipe option is provided to discard (gray out) data inside a given image region while losslessly preserving what is outside:Code: Select all
-wipe WxH+X+Y Wipe (gray out) a rectangular subarea of width W, height H starting at point X,Y.
-
- XnThusiast
- Posts: 4132
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Basic understanding of "JPEG Quality"?
And if Use estimated original quality (when possible) is used?
0.85*0.85*0.85 = 61%?
Or close to no additional loss?
0.85*0.85*0.85 = 61%?
Or close to no additional loss?
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
It depends. Let's say your JPEG that was previously saved without chroma subsampling i.e. 1×1,1×1,1×1 (best quality). Re-saving/re-encoding this JPEG with a SubSampling factor of 2×2,1×1,1×1 (default) inevitably introduces additional loss in quality. As mentioned before, the Use estimated original quality if possible setting only takes the (estimated) “quality factor” (1 – 100) into account.
-
- Moderator & Librarian
- Posts: 6366
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Basic understanding of "JPEG Quality"?
You do not have the required permissions to view the files attached to this post.
-
- XnThusiast
- Posts: 4132
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Basic understanding of "JPEG Quality"?
XnTriq wrote: ↑Thu Jan 21, 2021 11:30 pmLet's say your JPEG that was previously saved without chroma subsampling i.e. 1×1,1×1,1×1 (best quality). Re-saving/re-encoding this JPEG with a SubSampling factor of 2×2,1×1,1×1 (default) inevitably introduces additional loss in quality. As mentioned before, the Use estimated original quality if possible setting only takes the (estimated) “quality factor” (1 – 100) into account.
The XnView file 'info' displays 'Subsampling', so in principle that could be read and an image resaved using Use estimated original quality (when possible) with the same subsampling, even if you say that is not implemented now?
But what, if an image were resaved with the same subsampling 10 times, would you expect the quality of the resulting image to be: 0.107, a substantial loss of quality?