Home > Archive > Compression > November 2007 > How to determine JPEG quality level?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to determine JPEG quality level?
|
|
|
| Hello. I'm not an expert in compression, but rather a photographer,
color scientist, and novice programmer. I have read in numerous places
that it is difficult, if not impossible, to determine the quality
level of a JPEG file (i.e. the quality level that it was save as).
Photoshop happens to save the quality level as metadata which is
easily extracted, but other than that, there doesn't seem to be an
easy way to determine it.
My question is "why"? I understand only some of the basics of how JPEG
works, but I don't understand why it is difficult to determine the
quality level. Doesn't the decompressor need to know this somehow?
Isn't there some way to determine quality level from the number of
coefficients per block in the file? What about compression ratios?
I am using imagemagick to get info from JPEG files and I can extract
some data about JPEG:
Jpeg:sampling-factor: 2x1,1x1,1x1
Could that be used somehow to determine quality level of the JPEG (I
don't really understand what it is telling me)? My goal is to try and
find out if the image was saved with a quality level greater than or
equal to Photoshop's quality level 8 (whether it was saved in
Photoshop or not).
Any explanations/help will be greatly appreciated. Thanks in
advance...
Ken
| |
| Pete Fraser 2007-11-16, 9:56 pm |
|
"PTKen" <k-fleisher@nga.gov> wrote in message
news:9dde48dc-6680-4cf6-bab1-5a81b3e6e3cb@o6g2000hsd.googlegroups.com...
> Hello. I'm not an expert in compression, but rather a photographer,
> color scientist, and novice programmer. I have read in numerous places
> that it is difficult, if not impossible, to determine the quality
> level of a JPEG file (i.e. the quality level that it was save as).
> Photoshop happens to save the quality level as metadata which is
> easily extracted, but other than that, there doesn't seem to be an
> easy way to determine it.
It's really quite easy to find the quality level of a JPEG file.
The quality is determined by the quantization table.
The quantization table is included as part of the file.
>
> My question is "why"? I understand only some of the basics of how JPEG
> works, but I don't understand why it is difficult to determine the
> quality level.
It's trickier to find the quality level of a file that has been compressed
as JPEG, but now is in another format.
> Doesn't the decompressor need to know this somehow?
> Isn't there some way to determine quality level from the number of
> coefficients per block in the file? What about compression ratios?
Compression ratio is trickier.
With any given quality (i.e., quantization table) the compression ratio
will vary a lot depending on the subject matter.
>
> I am using imagemagick to get info from JPEG files and I can extract
> some data about JPEG:
>
> Jpeg:sampling-factor: 2x1,1x1,1x1
>
> Could that be used somehow to determine quality level of the JPEG (I
> don't really understand what it is telling me)?
It's telling you that the chrominance is subsampled by a factor
of two horizontally. In video terms this is known as 4:2:2.
> My goal is to try and
> find out if the image was saved with a quality level greater than or
> equal to Photoshop's quality level 8 (whether it was saved in
> Photoshop or not).
Equating levels between Photoshop and othe applications
can be tricky. Most applications us a single quantization
table and scale the values up or down to change the quality.
Some applications change the "shape" of the table as the quality
changes. If two applications start with different shapes of table
you can't really do a direct (easy) quality comparison.
Many applications use the suggested table in the standard.
Photoshop doesn't.
>
> Any explanations/help will be greatly appreciated. Thanks in
> advance...
This is a great novice programmer project. First use a binary
editor (010 Edit ot UltraEdit) to look at a JPEG file.
Download the JPEG spec for free (ITU-T T.81) and read the
section that deals with quantizing tables. The quantizing table
marker is 0xFFDB. It should be possible to search for this string
and see the values of the following quantizing table.
You may get multiple DQTs. Sometimes files contain multiple
images (main and thumbnail), so each image will have its own DQT.
You also can have one table per image per color component.
Typically the Y and C tables are combined in one DQT
(0xFFDB0084.....) but sometimes you will find a DQT for Y and
a DQT for C (0xFFDB0043..........FFDB0043......).
Play around with the editor for a while, then write some code to
parse the file, extract the tables, zig-zag scan them, and print the
result as an 8x8 matrix. This will be a great exercise, and give
you a good idea of how the mechanism works.
Pete
| |
| Willem 2007-11-16, 9:56 pm |
| PTKen wrote:
) Hello. I'm not an expert in compression, but rather a photographer,
) color scientist, and novice programmer. I have read in numerous places
) that it is difficult, if not impossible, to determine the quality
) level of a JPEG file (i.e. the quality level that it was save as).
) Photoshop happens to save the quality level as metadata which is
) easily extracted, but other than that, there doesn't seem to be an
) easy way to determine it.
)
) My question is "why"? I understand only some of the basics of how JPEG
) works, but I don't understand why it is difficult to determine the
) quality level. Doesn't the decompressor need to know this somehow?
) Isn't there some way to determine quality level from the number of
) coefficients per block in the file? What about compression ratios?
The only way would be to look at the quantization table. What JPEG does,
very crudely put, is round off the coefficcients so that lots of them turn
out to be the same and are therefore easily compressible. The higher the
level, the less rounding off occurs. Rounding off is done by this
quantization table, IIRC.
Here's a thought experiment for you: Save a file at 80% quality (or
whatever quality setting your program has), then load it again and then
save it at 99%. Now, looking at the file, suppose you can determine the
quality level. Would that be 80% or 99% ?
) I am using imagemagick to get info from JPEG files and I can extract
) some data about JPEG:
)
) Jpeg:sampling-factor: 2x1,1x1,1x1
That would be Color, Saturation and Valu (In that order, I think).
2x1 means that in the color band, a set of two pixels is put together as
one pixel before compressing. The idea is that the human eye can't see the
differences in color very well any way. However, look at a JPG picture
that has a very sharp edge between bright red and blue. A raytraced image
is good for this experiment. You'll notice ugly red blotches along the
edge. These disappear if you put all subsampling at 1x1.
So no, it can't be used to determine quality level. IIRC, it's a separate
setting that you can tweak in some programs. Not sure if Photoshop has it,
though.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
| |
| Industrial One 2007-11-16, 9:56 pm |
| On Nov 16, 6:47 am, PTKen <k-fleis...@nga.gov> wrote:
> Hello. I'm not an expert in compression, but rather a photographer,
> color scientist, and novice programmer. I have read in numerous places
> that it is difficult, if not impossible, to determine the quality
> level of a JPEG file (i.e. the quality level that it was save as).
> Photoshop happens to save the quality level as metadata which is
> easily extracted, but other than that, there doesn't seem to be an
> easy way to determine it.
>
> My question is "why"? I understand only some of the basics of how JPEG
> works, but I don't understand why it is difficult to determine the
> quality level. Doesn't the decompressor need to know this somehow?
> Isn't there some way to determine quality level from the number of
> coefficients per block in the file? What about compression ratios?
>
> I am using imagemagick to get info from JPEG files and I can extract
> some data about JPEG:
>
> Jpeg:sampling-factor: 2x1,1x1,1x1
>
> Could that be used somehow to determine quality level of the JPEG (I
> don't really understand what it is telling me)? My goal is to try and
> find out if the image was saved with a quality level greater than or
> equal to Photoshop's quality level 8 (whether it was saved in
> Photoshop or not).
>
> Any explanations/help will be greatly appreciated. Thanks in
> advance...
>
> Ken
Open the JPEG with GIMP, File > Save as JPEG, you'll get a quality
control slider and you can preview the image as you play around with
it, so just start from 100 and keep going lower until you notice the
image change. THAT's roughly the quality level it was originally saved
on.
|
|
|
|
|