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

Switch default interpolator to bicubic, improve speed/quality of binlinear (was: Documentation: interpolateWith) #289

Closed
mahnunchik opened this issue Oct 20, 2015 · 6 comments
Milestone

Comments

@mahnunchik
Copy link

Maybe it makes sense to mention in the documentation more clearly that:

  • bilinear interpolation is default interpolator
  • bilinear is not always suitable for reducing the size of images
  • bicubic usually provides better quality of reduced images
@lovell
Copy link
Owner

lovell commented Oct 20, 2015

Hello, yes this has come up a few times recently. A few other options could be:

  1. Experiment with reducing the level of pre-affine blurring when using bilinear to improve its quality and speed.
  2. Make bicubic the default interpolator.
  3. Both of the above.

@lovell lovell changed the title Documentation: interpolateWith Switch default interpolator to bicubic, improve speed/quality of binlinear (was: Documentation: interpolateWith) Nov 5, 2015
@lovell lovell added this to the v0.12.0 milestone Nov 5, 2015
lovell added a commit that referenced this issue Nov 15, 2015
Only use gaussian blur for non-linear interpolators

Improves performance of bilinear by ~15%

Add liborc to the packaged build to improve bicubic perf

Add examples of the various interpolation methods

Add bilinear vs bicubic to perf tests
@lovell
Copy link
Owner

lovell commented Nov 15, 2015

Commit 84fd1ca implements option 3. This brings a slight performance reduction for the default resize operation, but with much-improved quality. The bilinear option is, when manually selected, now considerably faster. I'll try to update the performance test results before v0.12.0 is published.

@lovell
Copy link
Owner

lovell commented Nov 22, 2015

The look branch has now been merged to the master branch pending release. Thanks for this suggestion!

@lovell lovell closed this as completed Nov 22, 2015
@puzrin
Copy link

puzrin commented Nov 28, 2015

@lovell just found this issue. Sorry if my question looks stupid. A there any reasons to not support lanczos3 filter for resize? Any better alternatives?

When implementing https://github.com/nodeca/pica, i've seen another list of presets in chromium skia (by speed):

  • Nearest neibor (Box)
  • Hamming
  • Lanczos, win = 2
  • Lanczos, win = 3

I'm not saying anything good or bad about algorythms, just try to understand relation between names and quality for common use.

@lovell
Copy link
Owner

lovell commented Nov 30, 2015

@puzrin Hi Vitaly, when downsampling/reducing, sharp always applies a small Gaussian blur prior to using the selected interpolator, which I believe is approximately equivalent to using a Lanczos 2 filter. This means sharp's default behaviour should be close to *magick's default Lanczos settings.

I've read somewhere that Lanzcos 3 can increase acutance/haloing when downsampling, but this probably depends on the input image, e.g. for text-as-an-image this may be a good thing. Perhaps a measure of entropy within an image could be used to select 2 vs 3, with a lower entropy favouring 3 over 2.

There are people who have spent a lifetime more than me studying filters and interpolators and image resizing in general. If you'd like to know more then please do ask this question over at the libvips repo.

The current plan is to switch sharp to the recently-improved vips_resize as part of #310 so sharp can be more in line with the behaviour of vipsthumbnail and its wisdom in such things.

As an (important) aside, thank you for helping to maintain the excellent js-yaml module. I was using it only last week, demoing its support for private types to some oblivious-then-envious Java-centric developers.

@puzrin
Copy link

puzrin commented Nov 30, 2015

@lovell I'm familiar with situation about hudge number of filters for different needs. Agree that blur + bicubic resampling gives similar result. Problem with this method is, that it contains "magical numbers" and those should vary on scale. Without statistics such euristic is not very cool. Pure lanczos3 is more predictable from the mathematical point of view.

AFAIK, lanczos3 is more common for downscale (+ unsharp mask after), and bilinear vs bicubic are popular only as start point because of simple implementation. I did't wished to create a new ticket about, because i'm not familiar how deep did you digged this topic before and i don't know your reasons to select blur + bicubic. But if you need any help - i'm ready to share everything i learned while writing pica.

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

No branches or pull requests

3 participants