Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".

Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T07:18:08+00:00

Donald Knuth (the creator of TeX, pronounced "teck") wrote: A language will not succeed without a good name. I have recently invented a very good name and now I am looking for a suitable language.

One can create variants of the popular tensor ("orthogonal") Lanczos resampling filter (Sinc-windowed Sinc 3-lobe) by changing the window function. ImageMagick offers a plethora of choices. There is one that I may have been the first one to try: Jinc-windowed Sinc.
It's not completely absurd to use Jinc as a windowing function when resampling images: From a frequency response viewpoint, the ideal filter in 2D is the Jinc function (used in a radial way, not tensor way). If one believes that self-windowing is best, one consequently wants to use the Jinc function for windowing. However, the Jinc function used as a radial filter gives a resampling scheme which is not interpolatory (which generally makes it a bit blurry). Given that a tensor product of Sincs is interpolatory, windowing the tensor Sinc function with the Jinc function would appear to make the best of a situation in which one wants a tensor Sinc to be interpolatory, but wants to keep Jinc as a window function from a 2D frequency response viewpoint.
-----
The above rationalization is most likely bunk. As Anthony Thyssen (and others?) has pointed out, small differences in windowing functions make even smaller differences in image results, and for this reason it's pretty hard to really know which windowing function is best (in general). Very very roughly, as one goes from top to bottom in the window functions shown in
Image (plot by Anthony Thyssen http://www.imagemagick.org/Usage/resize/#hann)
one decreases both sharpness and halo, and one increases jagginess (esp. when enlarging), at least when using three Sinc lobes (which is not surprising: basically you get a 2-lobe method when the window function is strongly bell shaped).
Again very approximately, the smoother (or blurrier) the image, the higher in the list one should choose a window function, and the more lobes one should use as well.
The first lobe of the Jinc function (which is not shown in the graph) is slightly more bell-shaped than the first lobe of the Sinc function (in the graph, Lanczos means Sinc windowing). The next one in the graph is the first lobe of the Cosine, which is right at the threshold of being bell shaped (it's concave all the way, with vanishing second derivative right at the limit of the window). (Aside: Cosine actually gives a pretty good window function if you are enlarging a blurry image.) In any case, one expects Jinc windowing to lead to slightly less haloing, and possibly a bit more jagginess, than Sinc (Lanczos) windowing. As it turns out, Jinc windowing unnoticeably affects jagginess (it may actually reduce it slightly?), and it reduces the haloing by an amount which is below JND in most images, at least when using sigmoidization, but nonetheless clearly visible in some cases, like the "firemen" image below. To a "devil in the details" kind of guy, this is enough to justify a good name.
In addition, Jinc-windowed Sinc does allow getting the same amount of halo suppression with a slightly lower value of the sigmoidization contrast.
The contrast value that makes an enlarged black square on a white background remain black within 2.3 JND (approximately [8,8,8] in 8-bit sRGB) is 11.6933.
With the usual warning that at this point only bleeding edge ImageMagick 7 compiled in HDRI mode is guaranteed to give best results, here is the code for the sigmoidized Ginseng ("Jinc-Sinc") scheme:
Code: Select all
magick input_small.png -colorspace RGB +sigmoidal-contrast 11.6933 -define filter:filter=Sinc -define filter:window=Jinc -define filter:lobes=3 -resize 300% -sigmoidal-contrast 11.6933 -colorspace sRGB Ginseng3.png

In this thread, I'll consider other test images from http://www.wisdom.weizmann.ac.il/~vision/SingleImageSR.html than those that I've already considered in http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=21660. All of them are 3x (300%) enlargements. Using Lanczos 3 (Sinc-windowed Sinc) with the same contrast gives very close results.
P.S. Warning: The test images are not very high quality. In particular, many contain a significant amount of haloing.
Last edited by NicolasRobidoux on 2012-08-27T06:15:23+00:00, edited 37 times in total.
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T07:34:49+00:00

What may not be bunk is doing this: You window the tensor Sinc with the radial Jinc. That is, you produce a mixed scheme: The filter is tensor (orthogonal), but the windowing is radial (EWA-like).
ImageMagick, wonderfully general and flexible as it is, is not set up to do this easily. (At least, I don't think it is.)
The attractive thing is this would give an interpolatory scheme, because it is the filter that determines the zero crossings, not the windowing function. And the zero crossings of the impulse response determine whether or not a scheme is interpolatory.
In my opinion this is very likely to produce a very high quality scheme. (Anthony? Fred? Opinions?) The reason is that the weakness of windowed Sinc methods in 2D may have to do with it resonating with the checkerboard mode. Windowing with a radial function would flatten the corners of the checkerboard, hopefully giving a less jaggy scheme without losing sharpness. (This is not even worthy of the back of an envelope. At best, this is back of a checkered restaurant napkin. But I am an optimist.)
Unfortunately I have things to finish before trying it, and programming this is likely to be nontrivial :(.
-----
In this thread, I'll be trying "poor man's ginseng" (Codonopsis pilosula): using Jinc as a tensor window, instead of a radial one.
P.S. I could probably fake the real thing with Gaussian windowing.
P.S. Actually, I can't fake it.
Last edited by NicolasRobidoux on 2012-08-23T12:50:15+00:00, edited 5 times in total.
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:20:50+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:24:59+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:31:55+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:36:30+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:39:13+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:45:09+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T08:45:27+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T09:41:34+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T09:46:15+00:00

3x:
Image
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-20T09:56:40+00:00

3x:
Image
P.S. If you enlarge this enlargement enough, you can see concentric "ripples" near the center. These high frequencies are actually in the original. I don't know how the small version of the "eyes" image was produced, but it sure looks like it involved low pass with a many tap filter. Many (all?) of the "originals" used at the Weinzmann site for testing show haloing, another fingerprint of negative lobe low pass downsampling. That is: The image that are being enlarged are not particularly close to what comes out of a digital camera or scanner. They are close to what one gets with commonly used methods of producing thumbnails.
Last edited by NicolasRobidoux on 2012-08-22T05:35:31+00:00, edited 3 times in total.
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-21T19:21:28+00:00

With Ginseng, the "safer" value (which only guarantees that an image which is pure black on the left and pure white on the right enlarges to such an image within 2.3 JND) is about 9.520945.
At that value, occasional "colour bleed" will occur. But generally none to be noticed, and people clearly like sharpness, and lower values "tighten" interfaces less, so this value may be a good starting point: if you want more sharpness, push the contrast up; if you want to get rid of colour bleed (and some of it is visible: it generally is invisible), push the contrast down. This rule of thumb works across the board with sigmoidization.
Funny enough, the ImageMagick rose: test image (which I believe was initially an RGB image, but which is tagged as sRGB within IM) gives rise to colour bleed.
Last edited by NicolasRobidoux on 2012-08-24T05:22:00+00:00, edited 2 times in total.
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby anthony » 2012-08-21T22:03:12+00:00

So do you really want to add "Ginseng" as a orthogonal window filter? Note that I do not plan to actually add any notes or examples of the filter, except to possibly say 'what it is' as an aside.

It is a relatively easy addition as all I need to do is fill in the above settings into the internal 'resize filter' tables, whcih define what functions and scaling factors needed to actually implement a filter.

This would most liking become automatically a radial Lanczos, Jinc-Jinc filter if used in 2D distort resizes.

So the real question is, will it be useful enough that it should be added?


As for my opinion... I have said in the past that typically I can't see much difference between most of the Windowed Sinc Filters, though there are a lot of them. I typically prefer to stick to default Lanczos, Mitchell for resize, and Robidox for Distorts, basically as they are tried and true. I prefer Robidox basically for its better interpolary effects for near no-op 2D filtered distorts.



ASIDE: I have re-generated all the examples in the resize section. Found a few duplicate images from different examples, and fixed them. But more importantally 'hann' is now what is listed in the graphs (and in the text). At least when the offical site updates with my upload.

You can see when I last generated ALL the examples in a section by looking at the automatically generated image in the signature at the bottom of that section.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8732
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Sigmoidized Ginseng (pronounced "Jinc-Sinc") resampling

Postby NicolasRobidoux » 2012-08-22T04:52:56+00:00

Anthony:
It's not as if orthogonal Ginseng (Jinc-windowed Sinc) will hit people over the head with a stunning display of resampling awesomeness when compared to Lanczos or other windowed Sincs, but it is a better scheme than Lanczos: It does manage to keep the same sharpness and jaggy reduction (I've scrutinized the differences with 3 lobes, but this should hold with more) with slightly smaller haloing. There is something about Sinc-windowed Sinc that makes the halo within "corners" worse than really needed.
So, although I did not expect it to be added as a standard scheme, I'd say: "Yay!". I do understand it's painless to add. It only possibly adds clutter.
-----
Is my "Yay!" good enough to be your "Yay"? Don't know. On most images, the differences will be hard to see. And sigmoidization decreases the difference (pretty much to about 8 in 8-bit sRGB, most of the time, when you use the stronger recommended version, and about 16 in 8-bit sRGB with the "safer" value, 10-20 being is what some apparently consider to be roughly the threshold of "noticeable" on a computer screen, and which fits my experience with an uncalibrated good quality Samsung monitor).
-----
I have not managed (yet?) to improve on Jinc as a window for Jinc, at least with my favorite number of lobes, 3. So, Ginseng could be strictly orthogonal. Although it would be "cute" to have "Ginseng" mean "use Jinc to window Sinc when orthogonal, Sinc to window Jinc when EWA".
I really don't know if EWA Sinc-windowed Jinc is any better than Jinc-windowed Jinc EWA. I doubt it very much. But this would work too: Having Ginseng mean Jinc-windowing (basically) within IM makes a lot of sense to me. And then it's just the usual Jinc Lanczos in EWA. Do I make sense?
Even better, Ginseng could be used to override the Sinc <-> Jinc windowing function substitution that automatically occurs when switching to EWA. You and I know that Sinc is an awful filter with EWA, so it should not touch the filter itself (Sinc for orthogonal, Jinc for EWA). This may be a very simple solution: Ginseng stands for Jinc-windowing with -resize, Sinc-windowing with -distort resize. That is, Ginseng would be a shortcut for "mix and match Sinc and Jinc in the most reasonable way given the context".
But of course this is easy to do with -defines so ???
-----
Aside:
When increasing the number of lobes, it actually makes sense to use a more bell shaped window function (the extreme version being Parzen = cubic B-spline). But this is another story.
-----
Thank you for all the resize code and doc fixes.
Last edited by NicolasRobidoux on 2012-08-22T07:48:08+00:00, edited 6 times in total.
NicolasRobidoux
 
Posts: 1939
Joined: 2010-08-28T11:16:00+00:00
Location: Copenhagen, Denmark

Next

Return to Users

Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 16 guests