Page 6 of 16

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-29T10:36:32-07:00
by NicolasRobidoux
imaggie wrote:...the ideal step filter that is the original aim...
Maybe, but it should not be the final goal.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-29T10:41:20-07:00
by NicolasRobidoux
http://cose.math.bas.bg/webMathematica/ ... lZeros.jsp

To get the Bessel1 function with cut off frequency = 1, you need to divide by pi. See my Axiom code above, or check the source code for ImageMagick's resize.c.

Note that I have a way of producing extremely accurate short polynomial approximations of the Bessel, trig and the like functions (again, an extension of something in the thesis of my student Chantal Racette). The ones in ImageMagick (for Sinc) are outdated: I have better ways now. (Will fix later: No time for this now.)

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-29T10:49:23-07:00
by NicolasRobidoux
imaggie wrote:...
Since it is the central lobe that does most of the work, the outer rings being progressively finer corrections, I would favour sinc over jinc as window fn. The jinc having a much faster decay envelop will probably degrade the essential central lobe more than sinc. I would suggest that the broader sinc lobe would generally be less destructive (in the sense of blurring the result) than a jinc window.

Of course there will be some test cases where this blurring may give a more pleasing result by, for example, softening staircasing on near horizontal lines. So some care needs to be taken in the choice of test image and the appreciation given to such features.
IMHO, this is why "sharpened" Jinc-windowed Jinc 4 EWA appears to give acceptable results with block graphic art ("old skool CG"), when I would guess that "sharpened" Sinc-windowed Jinc 4 EWA would suck. (But then, maybe without the sharpening Sinc- would beat Jinc-windowing?)

There is an engineer from eastern Europe who sells an image manipulation software tool which I once bought (forget the name of the tool/engineer) who implemented a method of his, itself an improvement on someone else's idea, which apparently works quite well, where the number of Lanczos lobes depended on the local smoothness of the image (or something like that: I forget the details). It would appear to me that maybe something like this would go along your thinking?

(Apologies for my rather terse/approximate comments...)

P.S. I tracked it down: It's the Data Dependent Lanczos method from http://www.general-cathexis.com/.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-29T11:05:29-07:00
by NicolasRobidoux
@Imaggie: Generally, I agree with all the "research" directions you point at, as well as all your comments RE: "wishy-washiness". The fact that I am proceeding (when I find the time) in slightly different directions, that is, that my first lines of inquiry are different, does not mean that I am not interested in progress being made along your lines of attack.

This being said, I am much more suspicious of frequency response arguments and arguments that originate from, say, sound processing, at least when upsampling, than most people. For example, the Mitchell-Netravali filter is a fine EWA downsampler, and an acceptable EWA upsampler, even though Keys splines fall completely outside of what's normally recommended frequency response wise. (Of course, it turns out to be a good approximation of rescaled Jinc-windowed Jinc 2...)

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-29T14:38:33-07:00
by NicolasRobidoux
I still like the maximally sharpened JInc-windowed Jinc 3 and 4. I have no clue if the relatively poor performance with some of the test images discussed on the Avisynth forum had to do with the fact that these images were sharpened and/or the result of downsampling with Lanczos3 or 4. Although one of them was the result of box downsampling, and for this one too the maximally sharpened ones did not do so well.

I'll try to keep checking how well/badly they do to figure it out, as I do other things.

But it would not be a bad idea, IMHO, to replace the current LanczosSharp with the maximally sharpened one. Sometimes, it appear that it will do just fine. (Apologies for the flip-flopping.)

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-29T14:40:14-07:00
by NicolasRobidoux
@Imaggie: In a way, windowing Jinc 3 lobe with Jinc gives what one would like Lanczos 2 to be like (more or less). Same with Jinc 4. So, you may be right that to have EWA Lanczos 3 behave more like orthogonal Lanczos 3 one would want to use a window which does not drop off as fast, like Sinc.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-30T10:09:51-07:00
by NicolasRobidoux
@Anthony: At this point, I don't think that Lanczos2Sharp and LanczosSharp should be "disappeared." However, I think that they need to be changed, and that a Lanczos4Sharp needs to be added.

Although they sometimes do have some undesirable aliasing, in many situations they are better than orthogonal Lanczoses, which says something. And "anyone" who uses a method with "Sharp" in the name should expect some aliasing.

The best candidates I have for them are the maximally sharpened ones, at this point.

But maybe a different windowing function (Sinc?) or a different blur < 1 would give better results.

If I get the go ahead, I'll do the changes in resize.c as soon as I find the time.

Note: I have not yet computed the "optimal" blur for Jinc-windowed Jinc 2. But this won't take me long.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-30T10:59:27-07:00
by NicolasRobidoux
I did another quick check, and really, there is little difference between Jinc-windowed Jinc and Sinc-windowed Jinc. The halos are a touch more pronounced with Sinc (barely).

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-30T11:56:16-07:00
by NicolasRobidoux
A less fragile alternative:

Change the blur of Lanczos2Sharp to 2/r2, and the blur of LanczosSharp to 3/r3.

Yes, the ground for doing this are flimsy. But this actually gives decent schemes, which don't interact badly with highly sharpened natural images (produced by downsampling with orthogonal Lanczos 3 or 4, for example).

The corresponding LanczosSharp is actually a very good method. So is the four lobe version.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-30T12:18:06-07:00
by NicolasRobidoux
Interesting: EWA Jinc-windowed Jinc 3 with blur 3/r3 gives results which are very close to orthogonal Sinc-windowed Sinc 3:

Code: Select all

convert original.* -filter Lanczos -resize 1000% oSincSinc3.png
convert original.* -define filter:filter=Jinc -define filter:window=Sinc -define filter:blur=.9264075766146 -define filter:lobes=3 -distort Resize 1000% JincSinc3blur3overr3.png
(Actually, all the sharpened EWA Jinc-windowed Jinc give results pretty close to orthogonal Lanczos, but this one a bit closer, in the eyeball metric, than the others.)

What this means is that the two are a good "blending pair."

It also suggests that a reasonable target for optimization would be (approximate) cloning of Sinc-windowed Sinc 3 (say) with Jinc-windowed Jinc etc.

(Next year.)

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-31T06:53:41-07:00
by NicolasRobidoux
It appears that if one rescales Jinc so its third root is at 3 (that is, use blur = r3/3), windowing with Jinc gives results closer to those obtained with windowing with Sinc.

So, if one aims to clone orthogonal Lanczos with EWA Lanczos, Jinc windowing is a better choice tham Sinc windowing.

In addition, EWA Jinc-windowed Jinc gives slightly less deep over- and undershoots than EWA Sinc-windowed Jinc.

I think I'm done trying any other windowing that Jinc.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2012-01-01T07:17:50-07:00
by NicolasRobidoux
After yet another batch of visual tests, this is what I have to say:

My initial doubts about the sharpened Jinc-windowed Jinc came from a batch of tests with re-enlargements of images produced by downsampling with orthogonal Lanczos. That is, they already had haloing, and a lot of local "sine like" oscillations near the critical frequency. The maximally sharpened Jinc-windowed Jincs do not shine on such images. The orthogonal Lanczoses, which in a sense match the downsampler perfectly, do well. Such images are not representative of the images one will use distort on.

The maximally sharpened Jinc-windowed Jincs are very good. But in my opinion, they are a bit too aliased/sharp. IMHO, the ones where the blur is n/r_n, with r_n the nth root of the n-lobe Jinc, strike a perfect balance. The "balanced" Jinc-windowed Jinc 4, in particular, is a very good method:

Code: Select all

convert rose: -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.943159799432847711 -define filter:lobes=4 -distort Resize 3000% JincJinc4blur4overr4.png
Compare with

Code: Select all

convert rose: -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=4 -resize 3000% oSincSinc4.png
IMHO, it's no contest. The maximally sharpened one is a nudge too boxy (but sharper):

Code: Select all

convert rose: -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.88451002338585141 -define filter:lobes=4 -distort Resize 3000% JincJinc4blur0p88451002338585141.png
The "balanced" 3-lobe version is also quite good:

Code: Select all

convert rose: -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=.9264075766146 -define filter:lobes=3 -distort Resize 3000% JincJinc3blur3overr3.png
Compare with orthogonal Lanczos 3 and the maximally sharpened EWA Lanczos 3:

Code: Select all

convert rose: -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=3 -resize 3000% oSincSinc3.png
convert rose: -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=.9264075766146 -define filter:lobes=3 -distort Resize 3000% JincJinc3blur3overr3.png
(I've not taken the time to look at the 2-lobe versions, but this would not take me long.)

Conclusion: Use n/r_n as blur for the EWA LanczosSharps. And, maybe, make the 4-lobe version the default EWA filter? (Maybe not if distort is used a lot for Old Skool CG, although the "balanced" EWA LanczosSharp is actually OK with those.)

Re: proper scaling of the Jinc filter for EWA use

Posted: 2012-01-01T12:03:59-07:00
by imaggie
I would expect 2 lobe versions to be too soft. They are cropped too early and deviate too much from the idea function to be sharp.

Be sure to give equal testing time to block graphics. Nice photos like rose: will be a lot less susceptible to harsh ringing and results may lead to conclusions that are not generally applicable. I would go as far as to suggest that no one "default" filter can be best for both cases.

It was the block graphic case that lead me to abandon lanczos4 in gimp orthogonal scaling.

It seems from your comments here that selecting "filter:filter=sinc" leads to orthogonal lanczos, is that correct ?

Re: proper scaling of the Jinc filter for EWA use

Posted: 2012-01-01T12:20:52-07:00
by NicolasRobidoux
imaggie wrote:...
It seems from your comments here that selecting "filter:filter=sinc" leads to orthogonal lanczos, is that correct ?
There are shortcuts for standard (orthogonal) Lanczos 2 (Sinc-windowed Sinc 2-lobes) and Lanczos 3 (Sinc-windowed Sinc 3-lobes):

Code: Select all

convert rose: -filter Lanczos2 -resize 3000% oSincSinc2.png
convert rose: -filter Lanczos -resize -resize 3000% oSincSinc3.png
To get higher number of lobes (say 4), I use the long form (shortcuts can be taken when you want a Sinc-windowed Sinc):

Code: Select all

convert rose: -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=4 -resize 3000% oSincSinc4.png
The "trigger" to use orthogonal filtering is using "-resize" instead of "-distort resize". See http://www.imagemagick.org/Usage/resize

-----

All the EWA sharpened (vertical/horizontal preserving, number of lobes/location of the last root, and maximally sharpened) Jinc Lanczos 3 and 4 do better than orthogonal Sinc Lanczos 3 and 4 with block graphics IMHO. There are halos, of course, but they are relatively mild and smooth, and the antialiasing is really mild given the sharpness. I stand to be corrected, and this can only happen if people try them with what matters to them.

One issue I've not addressed, and which may have a large impact on halos, is gamma correction. By default, IM does not push things through a gamma corrected toolchain.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2012-01-01T12:40:56-07:00
by NicolasRobidoux
Try this:

Code: Select all

cp ~/src/ImageMagick-6.7.0/images/logo-sm.png .
convert logo-sm.png -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.943159799432847711 -define filter:lobes=4 -distort Resize 1600% JincJinc4blur4overr4.png
convert logo-sm.png -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=4 -resize 1600% oSincSinc4.png
convert logo-sm.png -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.88451002338585141 -define filter:lobes=4 -distort Resize 1600% JincJinc4blur0p88451002338585141.png
convert logo-sm.png -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=.9264075766146 -define filter:lobes=3 -distort Resize 1600% JincJinc3blur3overr3.png
convert logo-sm.png -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=3 -resize 1600% oSincSinc3.png
convert logo-sm.png -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.88549061701764 -define filter:lobes=3 -distort Resize 1600% JincJinc3blur0p88549061701764.png