开发者

How can I know the jpeg quality of the read image using graphicsmagick

开发者 https://www.devze.com 2022-12-29 03:51 出处:网络
When I read a jpeg image using Magick::readImages(...) function. How can I know the estimated j开发者_如何学编程peg quality of the image?

When I read a jpeg image using Magick::readImages(...) function. How can I know the estimated j开发者_如何学编程peg quality of the image? I know how to set the quality when I wanna write the image, but it is not relevant to the quality of the original image, so for example: when I read a jpeg image that its quality is 80% and I write it using 90% quality I will get a bigger image than the original one, since the 90% is not 90% out of the original 80%. How can I know the jpeg quality of the read image?


This is impossible, period. The JPEG quality settings is just a number that is passed to the encoder and affects how the encoder treats the data.

It's not even percentage of anything - it is just some setting that affects how aggressively the encoder manipulates and transforms data. Wherever you see the percent sign near JPEG quality just ignore it - it's meaningless there.

So regardless of the encoder it is impossible to find which JPEG quality settings value the enocder used to produce this very image. The only way would be to obtain the original and try all reasonably possible setting values until you hit the same result.


It is neither impossible nor difficult with GraphicsMagick (or with ImageMagick). Type

gm convert -log %e -debug coder in.jpg junk.ppm

and look in the output for the line

Quality: nn

if the image was created by Independent JPEG Group software or

Quality: nn (approximate)

otherwise.

You can also use

gm identify -verbose in.png

and look at the

Quality: nn

line; however, this doesn't distinguish between exact and approximate qualities.


It's possible but difficult. The code has to examine the image just like people do. Here's a paper on the subject http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.4.4621&rep=rep1&type=pdf


If you want to read the JPEG metadata, you can use the following in command-line:

gm identify -format "%[JPEG-Quality]" your-photo.jpg

In C++, it might be using IdentifyImage : https://imagemagick.org/api/MagickCore/identify_8c.html#a91079e7db05c1bad53b2dbb2b01f41ba

That said, as other users said, it's just a number generated by the software that produced the image. As a matter of fact, I can see that GM 1.4 returns nothing on a JPEG without profile information, but GM 1.3.35 does a wild guess with jpeg.c/EstimateJPEGQuality/932/Coder (that returns 100%).

0

精彩评论

暂无评论...
验证码 换一张
取 消