Skip to content

About the JPEG encoding, decoding #5

@Nachimak28

Description

@Nachimak28

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions