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

Lossy compression for "free" ... #145

Closed
kodonnell opened this issue Dec 29, 2021 · 4 comments
Closed

Lossy compression for "free" ... #145

kodonnell opened this issue Dec 29, 2021 · 4 comments

Comments

@kodonnell
Copy link
Contributor

I'm not sure if this has been covered yet, but I think it's worth highlighting in the readme that it's very easy for a user to make QOI lossy for 'free'. That is, on encode, scale the image down by X, then encode with QOI, and on decode, decode with QOI then scale up by X. I'd be really interested to see a detailed comparison with JPEG (in terms of visual quality and size etc.), but for now my suspicion is this will be pretty compelling. For example, with X=2 I'm guessing we'd be around 4x smaller, and faster by 4x (less sampling speed which should ?? be minimal if we use simple algorithms). I'm guessing that'd put us around JPEG in terms of compression ratio, but oodles faster (as QOI is already a fair bit faster), and similar quality. I can have a play with this if there's interest - with the python implementation I have it should be pretty quick, once I get some reference images.

Anyway - for now I'm advocating putting something in the readme and publicising it, preferably after a little validation. Whether we incorporate it into the specification (basically just putting the value of X in a header, and maybe the sampling method?) and exactly how we'd do the sampling is probably a discussion that can happen after we've proven the idea.

@chocolate42
Copy link

It's probably better to do simple lossy by discarding the low bits of each value with shifts, but you crack on with experimenting as you please.

It won't be added to the QOI spec, that's finalised. Here is where ideas for new features are being discussed, good ideas might make it into some future format: https://github.com/nigeltao/qoi2-bikeshed/issues

@kodonnell
Copy link
Contributor Author

FYI results here - you can skip to the second table with JPEG comparisons. Assuming I didn't do anything silly, it's pretty compelling - you can get "similar" compression ratios to JPEG but a whole lot faster. (It depends on the JPEG quality setting, and how much you downscale for "lossy QOI".) That feels like at least mentioning in the readme, as it's somewhat unique to QOI (e.g. doing this with PNG wouldn't make sense as it's not as fast). But maybe it's just me = )

It's probably better to do simple lossy by discarding the low bits of each value with shifts

I thought that originally too, but wanted to do it without changing the format or this implementation, hence the scaling. But after thinking about it just then, I realised I could - I'll just shift the image before encoding it. Unfortunately, when dropping the last 3 bits (which gives similar SSIM to what I was looking at for the above method and JPEG) it's 4-5x slower and 2.5x worse compression than the above method. (Some of the encoding time could be memory layout stuff in numpy, but still not compelling.) But that's probably a discussion for that bikeshed repo ... and I guess doesn't ultimately change that it's potentially worth highlighting in the readme that QOI can easily be used as-is for lossy compression, and with compelling reason.

@phoboslab - can you close this if you disagree? I don't mind whatever you decide, but might as well close it if you disagree.

@dumblob
Copy link

dumblob commented Jan 12, 2022

and I guess doesn't ultimately change that it's potentially worth highlighting in the readme that QOI can easily be used as-is for lossy compression, and with compelling reason.

This is actually true for any lossless format. But yes, people do not know about it - e.g. pngquant.org has really good visual results (but it's extremely slow e.g. for use in smartphones for cameras).

@kodonnell
Copy link
Contributor Author

This is actually true for any lossless format. But yes, people do not know about it - e.g. pngquant.org has really good visual results (but it's extremely slow e.g. for use in smartphones for cameras).

True, but that's why I made the comment around why QOI is somewhat uniquely suitable to being able to do this usefully (unlike e.g. PNG).

@phoboslab phoboslab closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2022
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

4 participants