Implementing or using DSSIM within libvips #4221
Replies: 3 comments 4 replies
-
Hi @shun-recall, No, libvips doesn't have a ready-made SSIM operator, but it'd be easy in something like pyvips, just type in the equation (more or less). If you don't want to write and test SSIM yourself (understandable!), you could use numpy, I'm sure there are dozens of implementations to chose from. With skimage (first hit on google) you could do something like (untested): from skimage.metrics import structural_similarity as ssim
a = pyvips.Image.new_from_file("xxxxx.yyy")
b = pyvips.Image.new_from_file("zzzzz.yyy")
s = pyvips.Image.new_from_array(ssim(a.numpy(), b.numpy())) I'm a little wary of these metrics personally. The codec designers will have spent years (with SSIM, focus groups, expert panels, etc.) tuning everything and then giving you a single Q lever which balances file size against quality. As codec users all we really need to do is pick a pre-baked setting (IMO you only really need low / medium / high) for our application. For JPEG that's usually 70 / 75 / 85, with 90+ reserved for special cases like vector images. |
Beta Was this translation helpful? Give feedback.
-
Oh wait, sorry, what's in these PNGs? Alpha of course won't carry over, I expect you know. Vector art will always look a bit crappy as JPEG, and may not even be smaller. Photographs should work well, but they probably shouldn't be PNGs to start with. You could consider JXL or WEBP too. |
Beta Was this translation helpful? Give feedback.
-
I'm using C so not Python at the moment. I'm saving the images at memory buffers and not sure about what libvips functions I need to use to do the SSIM calculation. Could you give me some hints about how to implement it with C? Thank you very much for all your help John. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to optimise a collection of PNG images to JPEG and would like to choose the optimal quality to encode without degrading the visual quality.
I have found that some algorithms use DSSIM to compare the visual degradation of the encoded images.
Is something like DSSIM available or is it possible to do this with libvips?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions