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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: proper scaling of the Jinc filter for EWA use

Post by fmw42 »

perhaps it should be called "gensinc" :wink: or was that your "play on words"
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

My kingdom for a pun with legs!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Post by anthony »

NicolasRobidoux wrote:Anthony: Did I read right that you find results quite good with Bartlett-windowed Sinc?
No I meant with that when I was looking at windowed Sinc (for orthogonal 2-pass resize) I found little evidence that one was greatly better than others. It just seemed to me that windowing functions did their job of limiting the Sinc function, but everything else to be rather opinionated. But then again image resizing for generate is not something that is very qualitative.

However in EWA, the differences between windowing functions with various levels of blur, varies so widely that it is very difficult to see just what is good and what is not. Especially with a image like rose:

for example I do note that the default robidoux filter...

Code: Select all

   convert rose: -distort Resize 400% show:
is more alised than a simple 3 lobed Lanczos (Jinc-Jinc) filter

Code: Select all

   convert rose: -filter Lanczos -distort Resize 400% show:
I sort of expect it, as it is 'sharpened'.

Still is Robidox is still better than interpolation (bilinear as below or otherwise)

Code: Select all

  convert rose: -filter Point -distort Resize 400% show:
I still think it is a good idea to prevent blurriness in the NO-OP case.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Post by anthony »

Do you think it would be better to make EWA Lanczos, a Sinc Windowed Jinc rather than Jinc windowed Jinc?

Or would it just confuse the issue more than necessary.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

anthony wrote:Do you think it would be better to make EWA Lanczos, a Sinc Windowed Jinc rather than Jinc windowed Jinc?...
This may be the most sensible decision once the dust settles. I am not 100% sure yet that (unsharpened) Sinc-windowed Jinc is better than Jinc-windowed Jinc, but if so, it would be a natural thing to do to call it EWA Lanczos.

Or else you could make me a happy man and call it the "ginseng" filter. I suspect that no-one has really bothered to give a name to Sinc-windowed Jinc (you have precedents?) but if it's "new," we should get to name it.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

(Warning: Right now, all my visual tests involve enlarging the rose picture 30x.)

Opinion #1: Both un"blurred" Jinc-windowed Jinc 3 (the current distort Lanczos) and Sinc-windowed Jinc 3 appear to be excellent schemes if antialiasing is a top priority.

Of course, they are somewhat blurry. But it appears to me that sharpness is pretty good given the quality of the antialiasing.

Surprisingly, they give visually identical results on the rose 300x test. (Numerically, they are not very different.)

I suspect that either one is just about as good as it gets if antialiasing is the priority.
Last edited by NicolasRobidoux on 2011-11-16T11:12:05-07:00, edited 2 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

Opinion #2: The 1/sqrt(2) scaling for Jinc filters is definitely dead.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

Here is an illustration of just how good at low pass filtering the unrescaled Jinc-windowed Jinc EWA (current distort Lanczos) and Sinc-windowed Jinc EWA (future "Ginseng" scheme?) are:

Download Image. Now, try this:

Code: Select all

convert sl.png -filter Lanczos -distort Resize 3000% sl_JincJinc3.png

convert sl.png -define filter:filter=Jinc -define filter:window=Sinc -define filter:lobes=3 -distort Resize 3000% sl_SincJinc3.png

convert sl.png -filter Lanczos -resize 3000% sl_orthoLanczos3.png
Just like for the rose picture, switching the EWA window from jinc to sinc does not make a noticeable difference. However, both the EWA results are unbelievably more pleasant than the "classical orthogonal" Lanczos 3 result.

If the EWA Lanczos and Ginseng schemes can do this well with "old skool" CG, I'd expect them to do well with everything, provided the user is OK with some amount of softening.

With regards to the issue of blurring "hash patterns," I'd like to mention the following theorem (found in the Masters thesis of my student Chantal Racette; she is defending on the 2nd):
No resampling method (linear or nonlinear) can be simultaneously interpolatory (meaning that if you sample at an original pixel location you get back the original value) and preserve (the main) diagonals when additional pixels are added so as to double the sampling rate in both directions (preserving diagonals means that if your original image is constant on, say, rising diagonals, then the resampled image has the same property; the bit about doubling the sampling rate corresponds to half the people understand when enlarging an image by a factor of two).
As it turns out, the proof, due to yours truly, involves pointing out that a hash pattern is an image constant on both rising and descending diagonals, and at the intersection of such diagonals something must break.

In other words, if you want a scheme which does not show too much aliasing when you upsample sharp diagonal features, this scheme cannot preserve hash patterns. And since hash patterns are the highest frequency mode in an image, if you don't preserve them, you probably don't want to amplify them too much---you probably would rather blur them a bit, actually.

So, there you have it: Orthogonal Lanczos 3 is interpolatory and does not blur hash patterns but has jaggies galore when upsampling diagonal lines, and Jinc-Jinc and Sinc-Jinc EWA are not interpolatory, they blur hash patterns, and they do quite well with 45 degree lines.

For comparison, here is the code to generate the results with the two sharpened Sinc-windowed Jinc filters I've been discussing in this thread:

Code: Select all

convert sl.png -define filter:filter=Jinc -define filter:window=Sinc -define filter:lobes=3 -define filter:blur=.9264075766146 -distort Resize 3000% sl_SincJinc3Support3.png

convert sl.png -define filter:filter=Jinc -define filter:window=Sinc -define filter:lobes=3 -define filter:blur=.883751202473632831 -distort Resize 3000% sl_SincJincASharp.png
More aliasing, but still way better IMHO than orthogonal Lanczos 3. The latter, with the .88375... blur, is actually sharper looking than orthogonal Lanczos 3, but less aliased. Which means that we are escaping the zero sum game.

Now, the above are probably not the be all and end all of this story. But I am really starting to feel like we're getting somewhere. In particular, the Sinc-windowed Jinc 3 rescaled so that the extent is exactly 3 is looking like a pretty good compromise between aliasing and sharpness.
Last edited by NicolasRobidoux on 2011-12-29T12:38:32-07:00, edited 1 time in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

I'd be really curious to see what happens if Jinc is windowed with the Bessel J_0 function. But this is not something trivial to get out of ImageMagick.

P.S. Kaiser may be close enough.

P.S. ... and, with the default alpha value in ImageMagick (I've not tried anything else), works fairly well:

Code: Select all

convert sl.png -define filter:filter=Jinc -define filter:window=Kaiser -define filter:lobes=3 -distort Resize 3000% sl_JincKaiser3.png

convert rose: -define filter:filter=Jinc -define filter:window=Kaiser -define filter:lobes=3 -distort Resize 3000% rose_JincKaiser3.png
Kaiser-windowed Jinc 3 could be a winner.
Last edited by NicolasRobidoux on 2011-11-16T14:58:08-07:00, edited 4 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

Preliminary results suggest that (un-"blurred") Jinc-windowed Jinc is better than Sinc-windowed Jinc because it leads to smaller worst over- and undershoots. In other words, windowing with Jinc leads to slightly smaller haloing.

P.S. Indeed, JInc-windowed Jinc 3 has smaller over and undershoots where it counts than Sinc-windowed Jinc 3. So, the current EWA Lanczos is safe (for now).
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

Nicolas' conjecture of the day:

There is a value of alpha for which Kaiser-windowed Jinc 3 EWA will be a wonderful resampler. And this value of alpha will be smaller than the currently hardwired 6.5/pi (contrary to what some would think by only looking at frequency response).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: proper scaling of the Jinc filter for EWA use

Post by fmw42 »

So, there you have it: Orthogonal Lanczos 3 is interpolatory and does not blur hash patterns but has jaggies galore when upsampling diagonal lines, and Jinc-Jinc and Sinc-Jinc EWA are not interpolatory, they blur hash patterns, and they do quite well with 45 degree lines.

Have you considered a shape that is some kind of blend between orthogonal (square) and circular, such as a rounded square for the resampling area? Is that even feasible? Or a weighted average of the two (orthogonal and circular)

Just something that popped into my head when reading your post above.

Fred
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

fmw42 wrote: Have you considered a shape that is some kind of blend between orthogonal (square) and circular, such as a rounded square for the resampling area? Is that even feasible? Or a weighted average of the two (orthogonal and circular)...
Yes, I have.

For example, the GEGL scheme Nohalo blends an orthogonal scheme (which you can imagine to be based on squares) with an EWA scheme (the triangle filter) with weights that depend on the EWA ellipse.

I wish we would know enough what we want of a scheme that we could say: Computer, figure out the kernel (shape of the support, formula, values...) that will do what we want! But I don't really know "what we want." (Leonard Cohen's lover would say: "What's wrong with having it all?" The problem is that some properties clash, and in addition we don't really know what "all" should be.)

So, I build schemes which have some properties I want, and then I tweak them so that they have less of what I don't want.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

Kaiser-windowed Jinc EWA with

Code: Select all

#define Alpha
(7.0155866698156187535)
in resize.c (instead of the default
value 6.5) is a pretty good looking scheme.

Note that the chosen Alpha happens to be the second nonzero root of
the derivative of J_0 (the location of the extremum which is between
the roots that bracket the second positive lobe of J_0, which appears
to make sense given how the Kaiser window function is constructed;
these roots are at 5.5200781102863106496 and 8.6537279129110122170).
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: proper scaling of the Jinc filter for EWA use

Post by anthony »

I have a note in the sources to 'export' that alpha calculation.

That is add the alpha calculation for the Kaiser windowing function to the filter structure, and thus allow it to be set using a filter define. Much like I now have a filter defines to directly set the sigma of the gaussian function.

I could add that if you like, so you can adjust it more directly.

Update: Added it. For example... -define filter:alpha=7.3

Here is how you can plot the windowing function (not the actual weighting filter)

Code: Select all

  convert null: -define filter:filter=Box \
                     -define filter:window=Kaiser \
                     -define filter:alpha=8.0 \
                     -define filter:support=1.0 \
                     -define filter:verbose=1 \
                     -resize 2 null: >t.dat
  echo -e 'set grid; plot "t.dat" with lines; pause 100000;' | gnuplot &
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply