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

Progress on #118 (ignore aspect ratio) #191

Closed
skedastik opened this issue Apr 14, 2015 · 2 comments
Closed

Progress on #118 (ignore aspect ratio) #191

skedastik opened this issue Apr 14, 2015 · 2 comments
Labels

Comments

@skedastik
Copy link
Contributor

Happy to say I'm making good progress on feature request #118. Everything is working as intended and all tests are passing. There is one complication, however.

In ResizeWorker::Execute, sharp applies a Gaussian blur prior to large affine reductions. To do so, it generates a square Gaussian image based on the standard deviation of the residual. This is fine if the aspect ratio is preserved, but I suspect a square kernel is not suitable for "non-aspect" reductions.

I'd love to hear ideas on how to proceed. Thinking out loud:

  • Generate a Gaussian image based on the smaller residual (x or y), and box-shrink it to match the new aspect?
  • The kernel should probably have odd dimensions after the shrink.
  • If I'm not mistaken, libvips' separable convolution won't work for a non-square kernel, meaning non-aspect reductions won't be as optimized.

Also, I have to confess ignorance as to why a blur is applied prior to large affine reductions in the first place. Feel free to clue this image-processing newbie in.

@lovell
Copy link
Owner

lovell commented Apr 14, 2015

Hi Alaric, good to hear you're making progress.

The Gaussian blur is to reduce the effects of aliasing when performing a large affine reduction. I suspect you'll still need this if either x or y residuals are < 1.

If you've not already tried it, a quick approach might be to use the average of x and y residual factors as the single residual input to the sigma approximation. You'd need to manually inspect a few images to see how this looks, especially as the difference between x and y factors increases.

@skedastik
Copy link
Contributor Author

Good call on averaging the residuals. Here's the test image (512x512):

original

And results of down-scaling to the following non-integral dimensions (cropped and magnified):

results

The hard vertical edge is preserved in the first case which is perfect since no horizontal scaling occurs. The blur doesn't become perceptible until the x and y residuals reach more of a parity. These results were computed using the "nohalo" interpolator.

I'll go ahead with this approach in the provisional PR.

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

No branches or pull requests

2 participants