proper scaling of the Jinc filter for EWA use

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
@Anthony: Thank you much for fixing this bug.
P.S. Aren't I the one who started messing with Kaiser alpha values?
P.S. Aren't I the one who started messing with Kaiser alpha values?

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
I'm not saying that the other filters are not good, but a quick look suggests that unsharpened Jincwindowed Jinc 2 a.k.a.may be quite a good "light touch with just a bit of denoising/antialiasing/sharpening" downsampler for DSLR photographs. Definitely not "punch me in the face" sharp; more like a civilized gentleman.
(Yes, I know it's a bit on the blurry side for noop. I'm talking about linear light downsampling, here.)
Code: Select all
convert filter Lanczos2 distort Resize
(Yes, I know it's a bit on the blurry side for noop. I'm talking about linear light downsampling, here.)

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
I'm getting first pass results from Adam Turcotte's quantitative reenlargement upsampler comparison suite and, assuming we don't find bugs and that they hold when we extend the tests to other images than the "wave" test image, some of the results are both surprising and interesting. To be continued...

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
Always dangerous to make announcements based on early results, but I am really surprised at the ranks of the EWA Jinc Lanczoses "blurred" (sharpened, really) so that the radius is exactly the number of lobes.
Also, aliasing and all, RobidouxSharp appears to be quite a good reconstructor.

Let's see if this holds up with other test images. (Adam produces something like 70G of image results for each test image in order to compute the error stats, so this runs for a while.)
Also, aliasing and all, RobidouxSharp appears to be quite a good reconstructor.

Let's see if this holds up with other test images. (Adam produces something like 70G of image results for each test image in order to compute the error stats, so this runs for a while.)
 anthony
 Posts: 8855
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: proper scaling of the Jinc filter for EWA use
The sigma=1/2 is what is used for BOTH tensor (resize) and cylindrical (distort EWA) and produces exactly the same result (within rounding errors).
Using sigma=1/sqrt(2) actually produces smoother edges in extreme enlargements.
For example look at the output of
The second show practically no 'blocking' artefacts at all.
(distort or resize does not matter here)
Note also that 'Cubic' (BSpline) filter actually produces something that is close to a Gaussian sigma=0.65 that value is not exact and was just quickly determined roughly by eyeball.
I just made a note of this in IM Examples (not uploaded yet).
Using sigma=1/sqrt(2) actually produces smoother edges in extreme enlargements.
For example look at the output of
Code: Select all
convert logo: gravity center crop 80x80+0+0 filter Gaussian resize 800% show:
convert logo: gravity center crop 80x80+0+0 filter Gaussian \
define filter:sigma=.70710678 resize 800% show:
(distort or resize does not matter here)
Note also that 'Cubic' (BSpline) filter actually produces something that is close to a Gaussian sigma=0.65 that value is not exact and was just quickly determined roughly by eyeball.
I just made a note of this in IM Examples (not uploaded yet).
Anthony Thyssen  Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/
 anthony
 Posts: 8855
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: proper scaling of the Jinc filter for EWA use
NicolasRobidoux wrote:@Anthony: Thank you much for fixing this bug.
P.S. Aren't I the one who started messing with Kaiser alpha values?
Yeap, you were the 'instigator'. I was the programmer!
Anthony Thyssen  Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/
 anthony
 Posts: 8855
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: proper scaling of the Jinc filter for EWA use
NicolasRobidoux wrote:I'm not saying that the other filters are not good, but a quick look suggests that unsharpened Jincwindowed Jinc 2 a.k.a.may be quite a good "light touch with just a bit of denoising/antialiasing/sharpening" downsampler for DSLR photographs. Definitely not "punch me in the face" sharp; more like a civilized gentleman.Code: Select all
convert filter Lanczos2 distort Resize
(Yes, I know it's a bit on the blurry side for noop. I'm talking about linear light downsampling, here.)
When you have a summery you like to add or replace what I have in...
http://www.imagemagick.org/Usage/resize/#cyl_summary
Let me know.
Perhaps Adam Turcotte's final analysis
Anthony Thyssen  Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
More clean up: Here is the (de)blur that minimizes the maximum possible deviation from the identity under noop for Jincwindowed Jinc 2lobes: .88826421508540347.
This (de)blur is very likely to lead to a scheme that's too aliased for general use, but I want to test it for it's "reconstruction" properties. Since I already gave the corresponding (de)blurs for 3 and 4 lobes, I decided to complete the list.
Here is the Axiom code that figures out this value (through its reciprocal):
This (de)blur is very likely to lead to a scheme that's too aliased for general use, but I want to test it for it's "reconstruction" properties. Since I already gave the corresponding (de)blurs for 3 and 4 lobes, I decided to complete the list.
Here is the Axiom code that figures out this value (through its reciprocal):
Code: Select all
)cl a
digits 100
R1 := 3.831705970207512315614435886308160766564545274287801928762298989918839309519011470214112874757423127
r1 := R1 / %pi
R2 := 7.0155866698156187535370499814765247432763115029113138960553778269854960155020186630727149301794664578066071840984767118820251703769720326548673375642560309232023970190386543841800591275430452193373925
r2 := R2 / %pi
jinc x == besselJ(1,%pi*x)/x
sinc x == besselJ(1,x*(R1/r2))/x
l x == if (x<r2) then ( sinc(x) * jinc(x) ) else 0.
plus x == max(l x,0)
minus x == min(l x, 0)
f r == [ r, sqrt(1.+1)*r, 2*r, sqrt(1.+4)*r, sqrt(4.+4)*r, 3*r, sqrt(9.+1.)*r, sqrt(9.+4)*r, 4*r, sqrt(16.+1)*r, sqrt(9.+9)*r, sqrt(16.+4)*r, 5*r ]
z := l 1.e128
gplus(r) == _
( _
4 * _
( plus((f(r)).1) _
+ plus((f(r)).2) _
+ plus((f(r)).3) _
+ plus((f(r)).5) _
+ plus((f(r)).6) _
+ plus((f(r)).9) _
+ plus((f(r)).11) _
+ plus((f(r)).13) _
+ 2 * _
( plus((f(r)).4) _
+ plus((f(r)).7) _
+ plus((f(r)).8) _
+ plus((f(r)).10) _
+ plus((f(r)).12) ) ) _
) / _
( _
z + _
4 * _
( l((f(r)).1) _
+ l((f(r)).2) _
+ l((f(r)).3) _
+ l((f(r)).5) _
+ l((f(r)).6) _
+ l((f(r)).9) _
+ l((f(r)).11) _
+ l((f(r)).13) _
+ 2 * _
( l((f(r)).4) _
+ l((f(r)).7) _
+ l((f(r)).8) _
+ l((f(r)).10) _
+ l((f(r)).12) ) ) )
gminus(r) == _
( _
4 * _
( minus((f(r)).1) _
+ minus((f(r)).2) _
+ minus((f(r)).3) _
+ minus((f(r)).5) _
+ minus((f(r)).6) _
+ minus((f(r)).9) _
+ minus((f(r)).11) _
+ minus((f(r)).13) _
+ 2 * _
( minus((f(r)).4) _
+ minus((f(r)).7) _
+ minus((f(r)).8) _
+ minus((f(r)).10) _
+ minus((f(r)).12) ) ) _
) / _
( _
z + _
4 * _
( l((f(r)).1) _
+ l((f(r)).2) _
+ l((f(r)).3) _
+ l((f(r)).5) _
+ l((f(r)).6) _
+ l((f(r)).9) _
+ l((f(r)).11) _
+ l((f(r)).13) _
+ 2 * _
( l((f(r)).4) _
+ l((f(r)).7) _
+ l((f(r)).8) _
+ l((f(r)).10) _
+ l((f(r)).12) ) ) )
g x == gplus x  gminus x
[ g(1.12579115877571800+i*.000000000000000001) for i in 3..31 ]
 Residual for the one with least possible deviation:
g(1.125791158775718017)
 Actual blur value:
1/1.125791158775718017
Last edited by NicolasRobidoux on 20120501T07:50:2307:00, edited 3 times in total.

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
What is interesting although not altogether surprising (if you realize that the goal is to have a Jincwindowed Jinc which with an impulse response as close as possible to a Kronecker delta, and that the outer values are quite small no matter what) is that the (de)blur values for 2, 3 and 4lobes are very close to each other:They are all between 0.8845 and 0.8883, and seem to converge quickly.
Warning: This is a family of experimental schemes which may, or may not, give pleasant looking results. Use at own risk!
@Anthony: As discussed elsewhere, there are three broad groups of situations to consider when resampling: downsampling, near noop, upsampling. The above, on paper, are the EWA Jincwindowed Jinc tuned for noop. That is, they are the CatmullRoms of the Jincwindowed Jinc world (like RobidouxSharp is the CatmullRom of the EWA Keys world).
Code: Select all
convert INPUT.IMG filter Lanczos2 \
define filter:blur=0.88826421508540347 \
distort Resize PERCENT% OUTPUT.IMG
convert INPUT.IMG filter Lanczos \
define filter:blur=0.88549061701764 \
distort Resize PERCENT% OUTPUT.IMG
convert INPUT.IMG filter Lanczos \
define filter:blur=0.88451002338585141 \
define filter:lobes=4 distort Resize PERCENT% OUTPUT.IMG
Warning: This is a family of experimental schemes which may, or may not, give pleasant looking results. Use at own risk!
@Anthony: As discussed elsewhere, there are three broad groups of situations to consider when resampling: downsampling, near noop, upsampling. The above, on paper, are the EWA Jincwindowed Jinc tuned for noop. That is, they are the CatmullRoms of the Jincwindowed Jinc world (like RobidouxSharp is the CatmullRom of the EWA Keys world).

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
I'm finding that the behavior of a filter through linear light if quite different than not. No surprise here. But I need to do both before drawing conclusions.
And the above "sharpest" schemes, for most upsampling uses, really have very strong halos.
P.S. I suppose RobidouxSharp could be said to have the same issue. Uhmmm.
P.S.2 The really interesting thing is that the 4lobe version appears to have less haloing than the other two! I'm going to have to try optimizing the 5lobe version.
P.S.3 I used to think that Anthony was out of his mind to use Lagrange with a million lobes. Now, I'm starting to see that sometimes lots of lobes pay off?
P.S.4 Of course, the optimal blur has to be around .884 for the larger numbers of lobes! So I can have a look without running Axiom code. Kind of amazing to keep the same sharpness, but see the jaggies slowly disappear. (Well, past lobes=5 there seems to be diminishing returns.) Not sure it's much better. But sure is intriguing. I kind of feel like I'm seeing the theorywhich so often is such a crude approximation of what actually happenscome to life as the number of lobes is increased.
P.S.5 If you don't mind the halos, the "sharpest" Jincwindowed Jincs with large number of lobes are kind of amazing in terms of lack of jaggy combined with detail. No time to do a fullon comparison, but these "don't try this at home" schemes may actually amount to something.
P.S.6 Too many filters, too little time.
P.S.7 ... but, no real surprise here, if one want to minimize "worst case disaster", it's a competition between 3lobe and 4lobe. Bright circular blobs ring more than a bit with more lobes.
P.S.8 It appears that someone who can tolerate the "orthogonal" Sincwindowed Sinc 3 halos, can tolerate the "sharpest" EWA Jincwindowed Jinc 3 halos. Now I'm starting to see how things correspond. In terms of "flavor", the "sharpest" EWA Lanczos 3 is actually very close to its "orthogonal" cousin. I've not done enough tests to tell, but I would not be surprised if someone who does not know how to read artifacts would be unable to tell them apart. The correspondence is pretty amazing.
P.S.9 It blows my mind that my simple minded minimax deviation under noop criterion apparently allows me to clone orthogonal Lanczos with EWA Lanczos! Just like EWA RobidouxSharp apparently is a pretty good clone of orthogonal CatmullRom.
P.S.10 Now it's going to be really interesting to see how the quantitative errors that my student Adam Turcotte is computing line up
And the above "sharpest" schemes, for most upsampling uses, really have very strong halos.
P.S. I suppose RobidouxSharp could be said to have the same issue. Uhmmm.
P.S.2 The really interesting thing is that the 4lobe version appears to have less haloing than the other two! I'm going to have to try optimizing the 5lobe version.
P.S.3 I used to think that Anthony was out of his mind to use Lagrange with a million lobes. Now, I'm starting to see that sometimes lots of lobes pay off?
P.S.4 Of course, the optimal blur has to be around .884 for the larger numbers of lobes! So I can have a look without running Axiom code. Kind of amazing to keep the same sharpness, but see the jaggies slowly disappear. (Well, past lobes=5 there seems to be diminishing returns.) Not sure it's much better. But sure is intriguing. I kind of feel like I'm seeing the theorywhich so often is such a crude approximation of what actually happenscome to life as the number of lobes is increased.
P.S.5 If you don't mind the halos, the "sharpest" Jincwindowed Jincs with large number of lobes are kind of amazing in terms of lack of jaggy combined with detail. No time to do a fullon comparison, but these "don't try this at home" schemes may actually amount to something.
P.S.6 Too many filters, too little time.
P.S.7 ... but, no real surprise here, if one want to minimize "worst case disaster", it's a competition between 3lobe and 4lobe. Bright circular blobs ring more than a bit with more lobes.
P.S.8 It appears that someone who can tolerate the "orthogonal" Sincwindowed Sinc 3 halos, can tolerate the "sharpest" EWA Jincwindowed Jinc 3 halos. Now I'm starting to see how things correspond. In terms of "flavor", the "sharpest" EWA Lanczos 3 is actually very close to its "orthogonal" cousin. I've not done enough tests to tell, but I would not be surprised if someone who does not know how to read artifacts would be unable to tell them apart. The correspondence is pretty amazing.
P.S.9 It blows my mind that my simple minded minimax deviation under noop criterion apparently allows me to clone orthogonal Lanczos with EWA Lanczos! Just like EWA RobidouxSharp apparently is a pretty good clone of orthogonal CatmullRom.
P.S.10 Now it's going to be really interesting to see how the quantitative errors that my student Adam Turcotte is computing line up
Last edited by NicolasRobidoux on 20120501T07:52:4207:00, edited 4 times in total.

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
The "sharpest" EWA Lanczos looks just a bit more "jaggy" than the orthogonal one.
 anthony
 Posts: 8855
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: proper scaling of the Jinc filter for EWA use
When have I ever used Lagrange with a million lobes? All I did was ensure their were no limit to the order, just map support to lagrange order (as they were related) so you have an easy way to set the order. I suppose I could have had a 'filter:order' but then the specialised filter:sigma (for gaussian) and filter:alpha (for kaiser) was added later.NicolasRobidoux wrote:P.S.3 I used to think that Anthony was out of his mind to use Lagrange with a million lobes. Now, I'm starting to see that sometimes lots of lobes pay off?
I never much liked Lagrange, and even objected when BiCubic Interpolation (what is now Spline Interpolation) was replaced with a Largange Cubic instead of the expects Catrom Cubic. I only relented as I instigated that change (Spline blurs the images in noop lookups), and found the 'disjunction' of Lagrange to produce what I thought of as a 'useful' artefacts. I really need to look at and expand the 'point' inteprolation filters.
I hear you!P.S.6 Too many filters, too little time.
I look forward to it too!P.S.10 Now it's going to be really interesting to see how the quantitative errors that my student Adam Turcotte is computing line up
Anthony Thyssen  Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
Why did I get interested in the "sharpest" EWA Lanczoses again?
Because very preliminary quantitative results by my student Adam Turcotte suggest that the best reconstructor among the EWA Lanczoses were the sharpest ones previously tested, namely the ones deblurred so that the "radius" matches the number of lobes exactly, which I am again thinking may be a good "match" for tensor Lanczos 3, for example (hello jacobian adaptive GEGL).
Given that, I had to make sure Adam also tests the sharpest reasonable ones, so I computed the last of the "obvious ones" (two lobes). Then, I decided to have a second look.
Warning I do not believe that best reconstructor = best all around upsampler. At best, there is a strong correlation. No more.
Because very preliminary quantitative results by my student Adam Turcotte suggest that the best reconstructor among the EWA Lanczoses were the sharpest ones previously tested, namely the ones deblurred so that the "radius" matches the number of lobes exactly, which I am again thinking may be a good "match" for tensor Lanczos 3, for example (hello jacobian adaptive GEGL).
Given that, I had to make sure Adam also tests the sharpest reasonable ones, so I computed the last of the "obvious ones" (two lobes). Then, I decided to have a second look.
Warning I do not believe that best reconstructor = best all around upsampler. At best, there is a strong correlation. No more.
Last edited by NicolasRobidoux on 20120501T09:51:3707:00, edited 1 time in total.

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
False accusations. (Apologies.)anthony wrote:...
When have I ever used Lagrange with a million lobes?
...

 Posts: 1943
 Joined: 20100828T11:16:0007:00
 Authentication code: 8675308
 Location: Copenhagen, Denmark
Re: proper scaling of the Jinc filter for EWA use
(De)blurring EWA Jincwindowed Jinc 3 so that the EWA disc has radius exactly 3 gives a good looking scheme, which appears to have good quantitative properties, when measured on natural images, which I did not see coming. It has about the same amount of perceptual sharphness as orthogonal Lanczos 3.
"Current" EWA LanczoSharp = (approx) "next EWA LanczosSharp" = (approx) EWA Lanczos are better antialiased, but they can't really be described as orthogonal Lanczos3's twins.
It's EWA "LanczosRadius3" that may be the "orthogonal Lanczos 3 of the EWA world".
"Current" EWA LanczoSharp = (approx) "next EWA LanczosSharp" = (approx) EWA Lanczos are better antialiased, but they can't really be described as orthogonal Lanczos3's twins.
It's EWA "LanczosRadius3" that may be the "orthogonal Lanczos 3 of the EWA world".
Who is online
Users browsing this forum: No registered users and 2 guests