danielgtaylor / jpeg-archive

Utilities for archiving JPEGs for long term storage.
1.17k stars 121 forks source link

ms-ssim method ignoring target value? #101

Open davidenco opened 6 years ago

davidenco commented 6 years ago

I am using the default target of 0.9999 and the ms-ssim method, but I've noticed the output quality is always what the min setting is set to, as follows:

# ./jpeg-recompress --min 50 --method ms-ssim final.jpg original.jpg
Metadata size is 0kb
ms-ssim at q=72 (50 - 95): 0.980072
ms-ssim at q=60 (50 - 71): 0.970779
ms-ssim at q=54 (50 - 59): 0.965959
ms-ssim at q=51 (50 - 53): 0.963263
Final optimized ms-ssim at q=50: 0.939070
New size is 7% of original (saved 1044 kb)
#

If I specify the target and use the same value as the default, I get completely different results:

# ./jpeg-recompress --min 50 --target 0.9999 --method ms-ssim test.jpg original.jpg
Metadata size is 0kb
ms-ssim at q=72 (50 - 95): 0.980072
ms-ssim at q=84 (73 - 95): 0.989021
ms-ssim at q=90 (85 - 95): 0.993134
ms-ssim at q=93 (91 - 95): 0.995083
ms-ssim at q=94 (94 - 95): 0.995742
Final optimized ms-ssim at q=95: 0.995048
New size is 32% of original (saved 764 kb)
#
tssajo commented 5 years ago

@davidenco I am not the author of this program, but I figured this one out for you. If you look at the source code of jpeg-recompress then you can see that when no target parameter is passed via the command line then a target will be automatically set depending of the actual quality setting. Please see the source code of jpeg-recompress from line 117. You can see in there that the actual target value used also depends on the comparison method used. The target values are NOT the same for all the methods! So if you are using the 'ms-ssim' method then by default this target value will be used:

                case MEDIUM:
                    target = 0.94;

If you are specifying a target "by hand" on the command line (e.g. --target 0.9999) which is different than that value then the resulting output image will be different, too. FYI: 0.9999 is even higher than the VERYHIGH setting when using the ms-ssim method. Probably this is why you got a much larger image as a result. Please also note that the max value is set to 95 by default. So using ms-ssim with a very high target values such as target=0.9999 with no max set to e.g. 99, does not seem to make too much sense, after all. If you want more info regarding the min and the max settings then I suggest you read this blog post: https://mika-s.github.io/javascript/jpeg/compression/algorithm/2018/01/10/quality-min-and-max-with-jpeg-recompress.html