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

question:How to make an image compressed to a certain value #2492

Open
hunt-night opened this issue Oct 29, 2024 · 3 comments
Open

question:How to make an image compressed to a certain value #2492

hunt-night opened this issue Oct 29, 2024 · 3 comments

Comments

@hunt-night
Copy link

In my project, I want to compress images in bmp format, however, under the same encoder parameters the compression result of different photos varies a lot, is there any way to make the size of different images after encoding the same or the gap is small that is, the compression rate is fixed to a specific value

@vrabaud
Copy link
Collaborator

vrabaud commented Oct 29, 2024

Some images are easier to compress than others. That's why, for a similar quality (which is the encoding parameter in libavif), you can have AVIF images of different sizes, though they have the same bmp size (bmp sizes are only dependent on the image dimensions so I guess your input images have the same dimensions).

What you will have to do is try different encoding qualities (through binary search to be faster) so that you get equivalent sizes in the end. The visual qualities will be different though.

@hunt-night
Copy link
Author

Thanks for your reply
Can I assume that for different images of the same resolution in bmp format, it is possible that the original image itself will result in a compressed image with the same encoder parameters that will have one image with good compression and a high PSNR(computed by comparing the decompressed image to the original image), while the other image will have a relatively poor compression and a relatively low PSNR?

@vrabaud
Copy link
Collaborator

vrabaud commented Oct 29, 2024

No, for given encoding parameters, the quality should be roughly the same for normal photos: the quality you set in

int quality;
is responsible for the PSNR (there are a few other parameters here and there that can help too but this is the main one).

Then again, it depends on your data: even with a low quality parameter, a purely white image will be encoded with a good (maybe perfect) PSNR. What you describe is possible but for highly biased data, not random photos from the web.

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

2 participants