Repository navigation
Use decoded quantization tables for Jpeg encoding, store them in JpegMetadata #1705
Description
Activity
I'm already working on it, just need a confirmation on public API of
JpegMetadata.I like the proposal!
We should probably have a look at how JPEGsnoop determines quality so ours are not so inaccurate.
Reacted by Dmitry@JimBobSquarePants better to do as a separate PR I guess so it won't be much of a clutter.
- changed the title
[-]Jpeg default encoder (drastically) alters re-encoded image quality[/-][+]Use decoded quantization tables for Jpeg encoding, store them in JpegMetadata[/+]on Jul 17, 2021 Wouldn't more accurate evaluation negate the need to carry the tables?
You also need accurate quality evaluation in order to use the tables since you have to unscale these tables before copying to reuse in the encoder so that the user can re-encode them at a different quality.
The main problem with 'quality' is that there's actually no 'quality' property of jpeg. Many professional cameras use custom tables:
https://www.impulseadventure.com/photo/jpeg-quantization.htmlAny quality-evaluation algorithm is just an approximation built around standard table from ITU specification (I didn't check JPEGsnoop implementation). Extacting quality from non-standard table and then rescaling non-standard matrix would introduce a lot of errors like in the example above.
Main idea of this proposal is to carry the tables if we don't want to alter 'quality' level. So we can potentially have 3 scenarios:
- User provided 'quality' multiplier as encoder option - we must use it with standard table even if we had non-standard (this can have a discussion tbh)
- Standard table - we only need to store the quality multiplier as scaling default matrix with it would result in the same result -> no space wasted for standard matrix case
- Non-standard table - save table and estimate quality because we have it in the metadata (I would prefer to rename
QualitytoEstimatedQuality/ApproximateQualitymarkingQualityobsolete)
P.S.
Providing such API internally would bring the ability to alter tables on per-image/per-encoder basis but it's an another story.Checked JPEGsnoop quality evaluation implementation - it's nice, really nice. I will port it and open a draft PR so we can discuss what to do with saving tables.
Prerequisites
DEBUGandRELEASEmodeDescription
https://user-images.githubusercontent.com/20967409/126037087-16a8bd51-8cc5-46c8-ab8a-e66d625a8595.jpg
This image gains a lot of noise after
decode-encodescenario (you better download it and magnify with some app or use a histogram):Steps to Reproduce
Image above with:
Cause
Given photo uses some really strange quantization tables:
Non-standard tables are not a problem but current
QualityEvaluatormisses this one quiet drastically:So now we have 2 problems:
Proposal
Save decoded jpeg quantization tables to the jpeg metadata and use it as backup in the encoder: