pierrepo / MalariaSmearSearch

Blood smears database for malaria diagnosis :microscope:
GNU General Public License v3.0
1 stars 0 forks source link

Preserve image jpg quality when creating chunks #154

Closed pierrepo closed 7 years ago

pierrepo commented 7 years ago

When creating the chunks, we must preserve the quality of jpg images.

For small images, the size of the uploaded image should be the same as the size of the chunk.

This link might help: How to adjust the quality of a resized image in Python Imaging Library?

nanls commented 7 years ago

there is the same phenomena for png (in the other hand, we should not have png, right ?). But it seems, that PNG is a compressed lossless format. So setting optimize parameter as True (seems to be the default) save space without losing quality.

Did you understand the same thing ? http://pillow.readthedocs.io/en/3.0.x/handbook/image-file-formats.html#png

nanls commented 7 years ago

Note about the quality parameter :

from the doc, it is said that :

quality : The image quality, on a scale from 1 (worst) to 95 (best). 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.`

pierrepo commented 7 years ago

You are right. PNG is a lossless format. PIL might find a better compression strategy than the original file, that is why files saved by PIL could be smaller than the original file (but there shouldn't be a big difference in size). For the JPG file, a image quality of 95 seems optimal here. The default value of 75 explains why we have sometimes smaller files. Since the behaviors of both image formats are a bit different, you might have to write two different save() functions.

pierrepo commented 7 years ago

Actually, we could ignore png file format. No microscopy image would be an png file.