proper scaling of the Jinc filter for EWA use

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-27T08:37:18+00:00

@Anthony: Thank you much for fixing this bug.

P.S. Aren't I the one who started messing with Kaiser alpha values? :-(
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-28T09:50:47+00:00

I'm not saying that the other filters are not good, but a quick look suggests that unsharpened Jinc-windowed Jinc 2 a.k.a.
Code: Select all
convert -filter Lanczos2 -distort Resize
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 no-op. I'm talking about linear light downsampling, here.)
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-29T06:42:49+00:00

I'm getting first pass results from Adam Turcotte's quantitative re-enlargement 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...
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-29T11:18:42+00:00

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.)
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby anthony » 2012-04-29T19:21:27+00:00

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
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:


The second show practically no 'blocking' artefacts at all.
(distort or resize does not matter here)

Note also that 'Cubic' (B-Spline) 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/
User avatar
anthony
 
Posts: 8729
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Postby anthony » 2012-04-29T19:22:39+00:00

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/
User avatar
anthony
 
Posts: 8729
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Postby anthony » 2012-04-29T19:26:20+00:00

NicolasRobidoux wrote:I'm not saying that the other filters are not good, but a quick look suggests that unsharpened Jinc-windowed Jinc 2 a.k.a.
Code: Select all
convert -filter Lanczos2 -distort Resize
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 no-op. 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/
User avatar
anthony
 
Posts: 8729
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-30T12:59:22+00:00

More clean up: Here is the (de)blur that minimizes the maximum possible deviation from the identity under no-op for Jinc-windowed Jinc 2-lobes: .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):
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.e-128

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 2012-05-01T07:50:23+00:00, edited 3 times in total.
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-30T13:10:03+00:00

What is interesting although not altogether surprising (if you realize that the goal is to have a Jinc-windowed 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 4-lobes are very close to each other:
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
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 no-op, upsampling. The above, on paper, are the EWA Jinc-windowed Jinc tuned for no-op. That is, they are the Catmull-Roms of the Jinc-windowed Jinc world (like RobidouxSharp is the Catmull-Rom of the EWA Keys world).
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-30T16:11:21+00:00

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 4-lobe version appears to have less haloing than the other two! I'm going to have to try optimizing the 5-lobe 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 theory---which so often is such a crude approximation of what actually happens---come to life as the number of lobes is increased.

P.S.5 If you don't mind the halos, the "sharpest" Jinc-windowed Jincs with large number of lobes are kind of amazing in terms of lack of jaggy combined with detail. No time to do a full-on 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 3-lobe and 4-lobe. Bright circular blobs ring more than a bit with more lobes.

P.S.8 It appears that someone who can tolerate the "orthogonal" Sinc-windowed Sinc 3 halos, can tolerate the "sharpest" EWA Jinc-windowed 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 no-op criterion apparently allows me to clone orthogonal Lanczos with EWA Lanczos! Just like EWA RobidouxSharp apparently is a pretty good clone of orthogonal Catmull-Rom.

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 2012-05-01T07:52:42+00:00, edited 4 times in total.
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-04-30T19:11:57+00:00

The "sharpest" EWA Lanczos looks just a bit more "jaggy" than the orthogonal one.
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby anthony » 2012-04-30T21:46:14+00:00

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?


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. :-)

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 no-op 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.


P.S.6 Too many filters, too little time.

I hear you!

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 :-)

I look forward to it too!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8729
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-05-01T06:18:41+00:00

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.
Last edited by NicolasRobidoux on 2012-05-01T09:51:37+00:00, edited 1 time in total.
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-05-01T07:55:18+00:00

anthony wrote:...
When have I ever used Lagrange with a million lobes?
...
False accusations. (Apologies.)
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: proper scaling of the Jinc filter for EWA use

Postby NicolasRobidoux » 2012-05-02T08:30:33+00:00

(De)blurring EWA Jinc-windowed 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".
NicolasRobidoux
 
Posts: 1937
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

PreviousNext

Return to Digital Image Processing

Who is online

Users browsing this forum: No registered users and 1 guest