[SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc)

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Add Cosine windowing? (for Cosine-windowed Sinc)

Post by anthony »

NicolasRobidoux wrote:Looking at frequency response plots....
Ditto..

The 'Flat top' windowing function appears to be quite different to both tapered and untappered filters, and as a consequence, also have very different frequecy response to others. It is hard to track in the provided graph, but it is quite different. It seems more like a 'smoothed box' windowing filter.

The formula given seems overly complex (but that is the case for all the formula's listed in the Wikipedia Window Function Entry.

Any thoughts?
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: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

I don't see how getting equal frequency response near 0 will really help anything. (This being said, we're mostly shooting darts in the dark with the other window filters so...)
I've never seen it mentioned elsewhere than in the Wikipedia entry. (This being said, I'm not the right kind of signal processing expert.)
I really don't like the negative lobes of this window function. Which I suppose could be an argument for trying it. But I think the negative lobes of the window function are going to have rather drastic effects. Bad ones. But I can't know without trying.
Shoot a dart anyway? Because sometimes different is good?
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

Without the weird negative lobes, and forgetting about having a tiny nearly flat area near the middle of the freq. response plot, my eyeball says that one can basically get the same freq. response with Kaiser.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

Preliminary results of the quantitative re-enlargement suite of my student Adam Turcotte suggest that cosine windowing is among the best, although for 3-lobes Sinc is probably just a bit better, and for 4-lobes Sinc, Hamming is arguably better if you don't mind the slight gradient discontinuities when enlarging a lot, with Hann (which does not introduce gradient discontinuities) close behind.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

anthony wrote:...Do you have any info on whether three lobe is better than 4 lobe windowed sinc's?...
Very rough rule of thumbs when enlarging based on my limited experience:
1) The more bell shaped the window function, the more lobes you should use. Hamming is kind of an exception because it is far from zero at the end of the window: treat it as a non-bell shaped window, more or less like Bartlett. 5 lobes works well with some window functions.
2) Don't use lots of lobes with things that resemble pixel art or text, or noisy images, or low quality JPEG images. Conversely, the more "blurry" the image is, the more lobes you should use. This has to do with sub-critical images (that stay away from the Nyquist limit) VS critical images (with sharp lines and interfaces). For sub-critical images, 4-lobe Cosine, Lanczos and Hamming could be argued to be very slightly better than the 3-lobe versions; with critical images (very sharp features, or noise), it's the reverse.
My opinion is that if overall defaults for the number of lobes are to be set depending on the window function, it probably should be 3 lobes for Welch, Hamming, Cosine, Lanczos (and Ginseng), increasing from there up to, probably, 5 or 6 for Parzen. (I've not looked at this quite carefully enough. At some point, I could use the EXQUIRES software of my student Adam Turcotte to investigate more.)
Last edited by NicolasRobidoux on 2012-09-09T08:55:18-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: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

@Anthony: I was quite busy when this thread got longer, and did not read some of your questions and comments quite carefully enough. Will do. Apologies.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

I expect that ramping up the default number of lobes as suggested above will reduce the difference between the window functions.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

I erased my message by mistake :(
I believe that what it said was that Cosine, Welch and Lanczos works well with 3-lobe, but the other ones should use at least 4 lobes, possible as many as 5 or 6 with Parzen.
Basically (very rough rule of thumb, based on my limited experience): The more bell-shaped, the more lobes.
Last edited by NicolasRobidoux on 2012-09-12T06:05:49-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: Add Cosine windowing? (for Cosine-windowed Sinc)

Post by NicolasRobidoux »

anthony wrote:...The 'Flat top' windowing function appears to be quite different to both tapered and untappered filters, and as a consequence, also have very different frequecy response to others. It is hard to track in the provided graph, but it is quite different. It seems more like a 'smoothed box' windowing filter...
Any thoughts?
I don't think it's worth adding. All these window functions are primarily for 1D ("audio") signal processing, with a large number of taps (large number of "lobes").
I don't expect Flat Top to be any good with few (8 or less) lobes, at least compared to some of the other ones.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

Re: defaults.
It's really complicated.
If the image is critical (for example, it is obtained by downsampling a high quality digital photograph with nearest neighbour) and re-enlarged, Hann 2-lobe appears to be the most accurate windowed Sinc method (across all IM windowing methods and numbers of lobe among 2, 3 and 4).
So, should we assign defaults that reflect the "specializations" of the various windows? That is, have the default for Hann be 2?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by anthony »

At least this solved the problem as to why Lanzcos was three lobed while the rest of 4 lobes. Welsh was a later addition.

I have made Welsh, and Cosine default to 3 lobes, to join Lanzcos, while all the other filters remain 4 lobed by default. That includes Raw Sinc or Fast Sinc as 4 lobes by default though they probably should also should be 3 lobe.
Actually I don't think that last matters a lot. If you want a Raw Sinc, you should know what you you doing anyway.

Change in filter tables was uploaded to BOTH IMv6 and IMv7 SVN.

It makes the filter tables a little more complicated (using Lanczos to select SincFast with 3 lobe support, instead of a direct SincFast reference) but it is not a big change, and an extra comment hopefully makes it clear when the support value gets used.

I also added the following to the general Windowing Filter blurb...
All the functions (except 'Bartlett') form two basic catagories of windowing functions. However the catagories of windowing functions do not seem to be as important ast overall 'frequency response' you get from using a trigonometric defined curve.

A tapering 'bell' shaped curve, such as 'Hamming', 'Hann', 'Kaiser', 'Blackman', 'Bohman', and 'Parzen'.

And a untappered 'lobe' type windowing function which quickly falls to zero,
before being 'cut off' by the windows support, such as 'Lanczos', 'Welch', and 'Cosine'.

If you study the above window function graph you will see how the two styles of filter differ.

The tappering 'bell' shaped windowing functions will use a Lobes Support over 4 lobes of the Sinc Weighting function (or Jinc function in cylindrical (distort) resampling). The untappering 'lobe' type of windowing filters will default to using a 3 lobe support. This results in a rough equivelence between the two types of windowing filter, due to differnece in the windowing function roll off. This also means that the untappering windowed filters will be by default slightly faster that the tappering ones.

As a result of this 'support' difference, there is not a lot of difference visible in the graphs of the filter functions.

Of course if you want you can change the Lobes Support or even just the general support of any of the resize filters. They are all about the same only with very slight variations in ringing that will be generated.

...

I myself have not found a great deal of difference in results between these various windowing functions. From my reading of research papers the results seems to be more of a qualitative opinion of their suitability, rather than anything concrete. In summery, my feeling is that just about any windowing function can be used, but if I was to pick one you are better sticking to the most popular 'Lanczos' windowing filter, as it has good reasons (frequency spectrum response) for being a good choice as a resampling filter.
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: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by anthony »

NicolasRobidoux wrote:Re: defaults.
It's really complicated.
If the image is critical (for example, it is obtained by downsampling a high quality digital photograph with nearest neighbour) and re-enlarged, Hann 2-lobe appears to be the most accurate windowed Sinc method (across all IM windowing methods and numbers of lobe among 2, 3 and 4).
So, should we assign defaults that reflect the "specializations" of the various windows? That is, have the default for Hann be 2?

I prefer to try and follow the original settings from the "zoom" program that IM used to original define the filters. The major exception to that is the use of the name "Bessel" instead of "Jinc", whcih is much much much more accurate.

In this program, all Sinc filters used 4 lobe, except Lanczos whcih used 3. Until this discussion I did not know why. The change (just a few minutes ago) only effects "Welch" and "Cosine" windowing filters, and these were not part of the original "zoom" program. Now that I know the reason why Lanczos used 3 lobes, it becomes obviosu that these two filters also should be 3 lobes, and as such I have made the change to reflect that.

As for 2 lobe support. Really if you are going to use 2 lobe, my thinking is why use A Windowed sinc at all, you may as well use a cubic filter :-)

But it is easy enough to change the number of lobes, and a number of Specialized Lanczos Filters are already provided.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by fmw42 »

Anthony wrote:The major exception to that is the use of the name "Bessel" instead of "Jinc", whcih is much much much more accurate.
Actually, the Jinc is a Bessel function with a linear denominator. Thus Jinc is more accurate in this case than Bessel. But perhaps I misread your comment as to which you think is more accurate.

see http://mathworld.wolfram.com/JincFunction.html
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by anthony »

I could have said that better. Jinc is the offical term used in IM. bessel was what the "zoom" program used. Remember this program was written by the same person who have the original thesis for EWA resampling (Paul Heckbert).

The point was the function is more accurately named Jinc, instead of Bessel (which is actually still an alias for Jinc), and it was renamed to be Jinc when I reworked the filters specifically for adding Cylindrical Filters (for use in Distort which at the time was still blurry due to a bug, thanks Nickolas for you help there). Boy was I a novice in image filters back then! So many intricacies!

Anyway it was one of the few things I changed from what was in the original zoom program. The other BIGGER fix at that time was making windowing filters actually work as windowing filters. Believe it or not, Blackman was very similar to a Blurry Spline filter as the window function was being used directly! But that is now all ancient history.

The point in this topic is that another 'wriggle' to filters has been found, documented, and IM updated to correspond to it, and that is the reason Lanczos is 3 lobe by default in the original "zoom" program, and as a result Welch (spelling corrected) and Cosine, are also now 3 lobe by default.

Really to me it just makes all the Windowed Sinc filters even more 'uniform' in results with Lanczos slap bang in the middle. But then I am not personally that picky about filters. I am just trying to implement how it should be implemented, both for defaults, and for expert modification.
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: [SOLVED] Add Cosine windowing? (for Cosine-windowed Sinc

Post by NicolasRobidoux »

Typo in what I wrote earlier (and erased by mistake):
NicolasRobidoux wrote:...Hamming (not Hanning), Bartlett and Kaiser at least at 4...
Post Reply