Page 2 of 2

Re: no filter windowing when making an image smaller

Posted: 2011-03-15T09:17:50-07:00
by NicolasRobidoux
Possible conclusions:
  • No windowing with 3 lobes or more is no good for sinc and jinc (which Anthony, if not "everyone", knew already);
  • No windowing is OK with 2 lobes, at least with distort (EWA), if you value sharpness above most everything else;
  • "Matching" resize and distort filters often give results which are similar (which Anthony had mentioned before but that I had not seen with my own eyes);
  • Two lobe methods can be pretty good;
  • If you don't want noticeable haloing, resize Mitchell is hard to beat;
  • [/*]
  • My hope that some of the new distort (EWA) methods would OBVIOUSLY blow resize (tensor) out of the water when downsampling did not realize itself: the differences, at least with this test, are subtle. However, near diagonal interfaces and lines, EWA appears to do slightly better: lanczos 3 haloing, esp., is considerably smoother and has smaller amplitude when using the EWA (Jinc) version instead of the usual tensor (Sinc) version, and it's not obvious that there is something to be paid for this (at least when downsampling). EWA Lanczos 2 and variants (distort robidoux, lanczos2sharp, mitchell) also give good results.
It's going to take a more careful comparison to be able to draw more far reaching, definite, conclusions. But it looks like the zero sum game between blur, haloing and staircasing/moire is not something for which the new EWA methods provides and obvious way out.

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T08:47:02-07:00
by NicolasRobidoux
More or less, the conclusions so far match those of
http://imagemagick.org/discourse-server ... =1&t=17926

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T09:22:48-07:00
by NicolasRobidoux
Here is an attractive solution without any halo:

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter quadratic \
+distort affine '0,0,0,0 %w,0 800,0' \
quadratic_distort.png
It is pretty good when upsampling too. Pretty small support: the disk of diameter 3 (smaller than the support of resize lanczos2, which is the square of diameter 4, for example).

Code: Select all

-define filter:blur=.9428090415
(=sqrt(2)/1.5) also works well, although it is a bit too jaggy for my taste when upsampling.

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T15:50:43-07:00
by NicolasRobidoux
Amazing, EWA triangle (which sucks for upsampling), does a good job for this test image:

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter triangle \
+distort affine '0,0,0,0 %w,0 800,0' \
triangle_distort.png
With a support equal to the disk of diameter 2, this is most likely the fastest EWA (save nearest neighbour EWA, which I'm pretty sure will give dreadful results). On my crusty laptop, it runs in 1.720s compared to 1.523s for plain vanilla resize.

Honestly, I find extremely pleasing the result with EWA triangle. It is remarkably artifact-free.

Yes, EWA lanczos (or resize lanczos) is "snappier," but it does have obvious haloing, and it does have the "saturated" sharpened look, which EWA triangle escapes.

So, although my "no windowing needed when downsampling" hunch did not quite work out for sinc and jinc, it turns out that it does work for EWA triangle: there is no trace in the resulting image of the fact that the triangle basis function is not smooth (only continuous).

This also holds if using -filter triangle -resize, which gives slightly blurrier results which are otherwise fine.

(Most likely, I just rediscovered what some know already, namely that filtering with the hat function gives good results if one is far enough from upsampling. triangle, and quadratic, are approximations of Gaussian blur, esp. when used with distort, so the above is not that different from some of what is recommended here: http://www.imagemagick.org/Usage/resize/#best_filter.)

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T20:00:19-07:00
by anthony
Have you tried Hermite It is a 'smoothed' triangle filter.

Also you may like to try Gaussian with a 0.75 blur (sharpen) factor, which also generates a Hermite-like curve.

See http://www.imagemagick.org/Usage/resize/#filter_blur

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T21:20:40-07:00
by NicolasRobidoux
anthony wrote:Have you tried Hermite It is a 'smoothed' triangle filter.
My hunch was that Hermite would not give a good EWA filter (at least for downsampling).

I just tried, and hermite looks pretty good. However, hermite has the worst moire (in the shingles) of any scheme I've tried. This is not particularly surprising, because the hermite filter is heavily concentrated near the center (more so than triangle or the others) and consequently is "close" to "tight" box filtering.
This appears to confirm my rule of thumb that filter smoothness is not so important when downsampling.

(There was actually a theoretical logic to trying triangle: getting from box to B-Splines all the way to Gaussian by repeated box filtering, triangle is the second in the series, quadratic is the third, and cubic (B-Spline smoothing) is the fourth. I posited that when downsampling I could let go of one level of smoothness, which meant downgrading from quadratic to triangle, without paying a price. It appears I was right. Hermite is not directly an approximation of Gaussian.)

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T21:27:18-07:00
by anthony
Sounds like Lagrange filters!
Though Lagrange is not smooth.

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T21:31:40-07:00
by fmw42
Lagrange is an approximation to a sinc function, as I recall and so has large extent and would likely need windowing.

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T21:33:49-07:00
by NicolasRobidoux
... more stuff to try.

At some point, I'll have to try to put up a web site with a buch of tests results.

(Initial tests suggest that, at least with large support, Lagrange does not downsample well because of the sharp interfaces. With small support, it's OK. Also, with EWA, Jinc is the target, not Sinc.)

(And yes, Gaussian, with the right blur, should give good results.)

Re: no filter windowing when making an image smaller

Posted: 2011-03-16T22:33:46-07:00
by anthony
fmw42 wrote:Lagrange is an approximation to a sinc function, as I recall and so has large extent and would likely need windowing.
Lagrange is self windowing as it is a piece-wise function. In fact it is its support size (window size) that determines what its order (number of pieces) it has. A support of 0.5 is a box, support 1.0 is a triangle, support 1.5 which is like a discontinuous quadratic (3 pieces) and support 2.0 is Mitchell like (actually it is equivalent to bi cubic interpolation).

http://www.imagemagick.org/Usage/resize/#lagrange

Re: no filter windowing when making an image smaller

Posted: 2011-03-17T08:32:21-07:00
by NicolasRobidoux
anthony wrote:...
Also you may like to try Gaussian with a 0.75 blur (sharpen) factor
...
I agree that a tight Gaussian will also give good results.

"Quadratic EWA" is a cheap approximation of it.

Note that I like quadratic a lot, for a variety of theoretical reasons, even when using -resize---but it certainly is not very sharp. Sharpness can be restored with quadratic EWA by using, for example, blur=sqrt(2)/1.5, which appears to strike a good balance between sharpness and aliasing. In addition, quadratic resize and quadratic EWA give results which are very close, which should not be surprising since they both approximate Gaussian, the only method which is (if one ignores the different truncation) the same as an EWA or orthogonal method.