picheral / Zooprocess

Depository for Zooprocess developpers
3 stars 1 forks source link

Éviter de produire des JPEG avec une qualité de 100% #30

Open jiho opened 1 year ago

jiho commented 1 year ago

la qualité "100" n'est, en pratique, jamais utilisée pour JPEG : elle amène à une très forte dégradation du taux de compression pour un gain qualité non-mesurable. la valeur par défaut pour la qualité JPEG dans la méthode "save" de PIL est de 75, et la doc indique bien que "100" est à éviter:

quality The image quality, on a scale from 0 (worst) to 95 (best), or the string keep. The default is 75. Values above 95 should be avoided; 100 disables portions of the JPEG compression algorithm, and results in large files with hardly any gain in image quality.

jiho commented 1 year ago

Cela semble être stocké dans le fichier de config: https://github.com/picheral/Zooprocess/blob/b9235eb3c36bbbbde262ab84d2a7768d4dbc6ebc/macros/Zooscan_edit_configuration.txt#L108

Une solution cheap serait de passer à 95%.

Une solution probablement préférable serait de passer en .png pour tout.

picheral commented 1 year ago

Set the code to change the compression rate to 75 is easy and can be done rapidly.

The UVP5 and FlowCam codes can also rapidly be modified to save PNG images instead of JPG.

Le 05/01/2023 à 13:39, Jean-Olivier Irisson a écrit :

la qualité "100" n'est, en pratique, jamais utilisée pour JPEG : elle amène à une très forte dégradation du taux de compression pour un gain qualité non-mesurable. la valeur par défaut pour la qualité JPEG dans la méthode "save" de PIL est de 75, et la doc indique bien que "100" est à éviter:

quality
The image quality, on a scale from 0 (worst) to 95 (best), or the
string keep. The default is 75. Values above 95 should be avoided;
100 disables portions of the JPEG compression algorithm, and
results in large files with hardly any gain in image quality.

— Reply to this email directly, view it on GitHub https://github.com/picheral/Zooprocess/issues/30, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEM43ED4SRL4EVXSEUFHWH3WQ26GVANCNFSM6AAAAAATR5ABSI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

--

On the WEB : http://piqv.imev-mer.fr
http://ecotaxa.obs-vlfr.fr http://ecopart.obs-vlfr.fr http://uvpdb.ecotaxa.org https://aslopubs.onlinelibrary.wiley.com/doi/full/10.1002/lom3.10475 https://aslopubs.onlinelibrary.wiley.com/doi/10.4319/lom.2010.8.462

Marc Picheral, Research Assistant LOV, CNRS-Sorbonne Université Institut de la Mer de Villefranche sur mer 181, chemin du Lazaret 06230 Villefranche sur mer France mob. : 33 +6 51 87 09 99 tel. : 33 +4 93 76 38 08 tel. : 33 +4 93 76 38 57 ORCID : 0000-0001-8172-5473

jiho commented 1 year ago

75% may be a bit too compressed.

A quick test gives the following total size for ~50k Zooscan images: 410M 100_percent 223M 75_percent 244M 90_percent 274M 95_percent 310M png

So PNG with 0 loss of information gives a 25% size gain.

Here are a couple images at

100% quality

100_wp220210511_d2_1_1799 100_wp220210106_d1_1_93 And with compression

95%

95_wp220210511_d2_1_1799 95_wp220210106_d1_1_93

90%

90_wp220210511_d2_1_1799 90_wp220210106_d1_1_93

75%

75_wp220210511_d2_1_1799 75_wp220210106_d1_1_93

I feel 75% is giving a bit of blur and less dynamic range in the greys. 90% gives a 40% size reduction with much less/no visible loss. I'd go for 90 or 95%.

fchahun commented 1 year ago

The value usually adopted in the industry for "high quality JPEG" is 85%.

Based only on a couple of images, it is difficult to visually assess the degree of image quality degradation in the 75-95% range,

The PSNR metrics (available in some graphics library) is a commonly used metrics for image quality alteration, based on comparison of the original image and the compresssed/decompressed image. Being a log mesure (expressed in decibels), a higher value means less degradation. It is usually considered that a PNSR >= 40 means that image alteration cannot be detected by an human eye.

JPEG is an old image compression standard (1980) with many drawbacks. JPEG 2000, which takes advantage of 40 years of advances in applied math and computing, offers (among other things) a significantly better tradeoff between compression an quality. Unfortunately, it is not natively supported by Web browsers.