Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the JPEG encoding, decoding #5

Open
Nachimak28 opened this issue Apr 9, 2022 · 0 comments
Open

About the JPEG encoding, decoding #5

Nachimak28 opened this issue Apr 9, 2022 · 0 comments

Comments

@Nachimak28
Copy link

Referring to the issue in the README, saving the image as JPEG will inevitably apply some level of compression. So decoding the image to retrieve the exact pixel intensities of the original image may not be possible unless using lossless formats like PNG

However, I found a little parameter of PIL save subsampling while doing the JPEG compression which tries to maintain the pixel intensity, still incurring some loss but not as big as without this parameter.

Given codebase without subsampling

Original implementation: https://github.com/ternaus/base64ToImageConverters/blob/main/image2base64/converters.py
Line number: 12
format: 'JPEG', quality=100

im.save(buffered, format=image_format, quality=quality)

RGB Image:
download

Converted Image:
download

Mean difference of the assertion test: 125.74196689386562

With Subsampling parameter set to 0

im.save(buffered, format=image_format, quality=quality, subsampling=0)

RGB Image:
download

Converted Image:
download

Mean difference of the assertion test: 53.83414475819539

The visual as well as numerical difference in clear. JPEG will definitely lead to losses. But subsampling=0 can preserve more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant