Page 4 of 16

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-20T12:16:02-07:00
by fmw42

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-20T12:45:56-07:00
by NicolasRobidoux
Thank you Fred.

But yes, I've owned a copy of Abramowitz and Stegun since my undergraduate days.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-21T00:29:25-07:00
by anthony
NicolasRobidoux wrote:When it is an EWA (-distort) call, give them Jinc-windowed Jinc with blur = n/r_n, with r_n the nth root of Jinc. This gives a filter which is closer to what people expect (hope for, should I say) out of Lanczos, certainly less blurry than the current EWA Lanczos and Lanczos2. For example, the support of the EWA and orthogonal Lanczoses then have the same diameter. Again, the default number of lobes shoudl be 3.
-----
What do you think?
Actually I am not certain what to think! That specific blur formula essentially ensures that the filter is compressed
so that for a N node Jinc/Jinc filter the N'th root will be at 'N' from the origin. That is it has integer support.

For example a 8 lobe Jinc/Jinc blur factor will be 8/8.2453949139520427.
The that in effect shifts the filters support from the 8th zero crossing at 8.2453949139520427 to just 8.

I am not certain how this produces the best blur factor.

Hmmm. How about I change LanczosSharp to do this for however many 'lobes' is being used.

I am loathed to change the definition of EWA Lanczos, away form a straight unblurred Jinc/Jinc (or possibly Sinc/Jinc) as it is a very straight forward definition.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-21T07:01:10-07:00
by NicolasRobidoux
Anthony:

Exactly, it makes the EWA Lanczos with n-lobes have it's nth (last) root exactly at n, just like orthogonal Lanczos.

Suggestion: Look at the results. You yourself find the "un-sharpened" Lanczoses too smoothing. Compare with the above rule of thumb.

Given that people can still easily get Sinc-windowed Sinc (with no blur) directly if this is what they want (convert ... -define filter:window=jinc -define filter:filter=jinc -define filter:lobes=n ...; I imagine the same result can be obtained with a shorter command because of various defaults), it makes sense to me to have EWA Lanczos be something which is going to be more universally considered useable. Matching the EWA and orthogonal extents happens to do just that. In addition, it gives a reasonably straightforward correspondence: For matching number of lobes, the EWA halo extends exactly as far in the Manhattan metric as the orthogonal one. (Of course, the halos are less deep, and they extend less far---by sqrt(2)---in the Euclidean metric.)

-----

I'd rather you keep the LanczosSharp label for the ones that are even more sharpened (those that minimize worst case deviation for extreme values under no-op). When I have a minute, I'll make a table of all the sharpening blurs. We already know the one for Jinc-windowed Jinc 3 and 4. These new EWA LanczosSharp really perform like one would expect a sharp scheme to.

The above, of course, are suggestions/opinions.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-27T12:55:58-07:00
by NicolasRobidoux
I have posted pseudo-IM code for my favorite candidates here:
http://forum.doom9.org/showthread.php?p ... ost1541448

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-30T10:17:18-07:00
by NicolasRobidoux
Anthony:

I thought about it some more, and I agree with you that the Jinc Lanczoses (the "not sharp" ones) should be left alone.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-11-30T14:31:31-07:00
by NicolasRobidoux
Anthony:

When I have time, I'll make a table of the "no-op minimax" blurs for Jinc-windowed Jinc for all numbers of lobes from 2 to 8 (which I believe is the largest number of lobes that can be used in IM).

They don't work well will images that already have halos, but otherwise they are quite good.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-03T16:44:55-07:00
by NicolasRobidoux
Grrr! Sometimes, the new sharp Jinc-windowed Jinc lanczoses are too aliased.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-03T17:08:14-07:00
by NicolasRobidoux
I'm starting to think that across the board, one of the variations of "minimum deviation when the data is constant on vertical lines" (which is the basis of the current LanczosSharp and Lanczos2Sharp) is best.

Too much aliasing in some situations with the variants discussed in this thread. I don't know if the aliasing I see in some cases is representative of what happens "in typical situations," but I don't like it.

Ah well...

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-07T09:00:12-07:00
by NicolasRobidoux
As documented in http://imagemagick.org/discourse-server ... =15#p78866, the maximally sharp Jinc-windowed Jinc don't do well resampling already sharpened images.

I don't know if this means that they are not worth having as built-in methods, and I'm leaving this research direction aside for a while.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-09T20:32:49-07:00
by NicolasRobidoux
Mark (user markanini on the Doom9 forumhttp://forum.doom9.org/showthread.php?p ... ost1544046 made me realize that there is one task for which I have no idea whether the maximally sharpened Jinc-windowed Jinc EWA filters would shine: downsampling (a lot).

Unfortunately, I have not time for such tests now. But this is my "note to self."

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-19T09:44:59-07:00
by imaggie
Quite a coincidence seeing this being actively discussed just now . I'm looking at this question of jinc-jinc vs sinc-jinc and window fn extent.

Am I correct in thinking your conclusion is that they both seem to perform similarly in quality but that jinc-jinc falls off rather too quickly , giving problems when the kernel is relatively small?

Is there a generalised expression for determining where the zero crossings of jinc are?

I'm making , probably simplistic, comparisons to Lanczos window ( ie sinc-sinc not the IM recasting of what Lanczos means) . As you're probably aware lanczos window is chosen to have it's zero point at a zero crossing of the base sinc fn.

To ensure smooth cut-off, I'm assuming it is desirable to do the same with sinc-jinc (gensing ;) ) windows.

Thanks for any clarifications.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-19T16:46:26-07:00
by anthony
Imagemagick has a internal table of the first 20 zero crossings of the Jinc Function. The "filter:lobes" expert setting can be used to define the support size of a jinc function (used by default for cylindrical, or distort image resizing) in terms of the values of this table, when the main function is Jinc.

When Jinc is used as a windowing function the first zero crossing is scaled to envelop the support of the main weighting function (of however many 'lobes' are specified (current default is 3 but may canvas to 4 due to the previous discussions). It is also possible to set the 'support' the windowing function will be scaled to, to something different than the actual support used for the main filter. See the "win-support" expert setting.

See IM examples Filter lobes
http://www.imagemagick.org/Usage/resize/#filter_lobes
and Distort Resize
http://www.imagemagick.org/Usage/distort/#resize
http://www.imagemagick.org/Usage/resize/#distort
and Cylindrical Filters
http://www.imagemagick.org/Usage/resize ... ylindrical
For a summery of expert options see
http://www.imagemagick.org/Usage/resize/#filter_options

For example you can force the use of a Sinc windowed Jinc EG:

Code: Select all

   -filter Jinc
   -define filter:window=SincFast
   -define filter:lobes=4
For example...

Code: Select all

  convert xc: -filter Jinc  -define filter:window=SincFast \
             -define filter:lobes=4 -define filter:verbose=1 \
             -distort resize 200% null: | grep '^#'
# Resize Filter (for graphing)
#
# filter = Jinc
# window = SincFast
# support = 4.24106
# win-support = 4.24106
# scale_blur = 1
# practical_support = 4.24106
Weather a cylindrical Lanczos (or whatever name it is) should be a Jinc windowed Jinc, OR a Sinc windowed Jinc is the main topic of discussion. My myself do not have the expertise to comment, but am open to the addition and adjustment of 2-d Windowed Jinc Filters, to better improve the results of image distortion, especially for near unity scaled distortions.

I tried very hard to make the expert filter controls as versatile as possible. Something that has been put to good use by Nicholas and others, so as to develop improved filters, especially when using 2-dimensional cylindrical (distort) filtered resizes.

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-19T18:38:37-07:00
by NicolasRobidoux
imaggie wrote:...I'm looking at this question of jinc-jinc vs sinc-jinc and window fn extent...
Just in case you don't know already:
Rule of thumb
  • (Windowed)-Sinc give are garbage when used as EWA filters.
  • (Windowed)-Jincs are not good when used as orthogonal filters.
Like any rule of thumb, there may be exceptions. But I don't know of any (which does not mean that I don't stand to be contradicted).

Before you start thinking about whether Sinc or Jinc is better and why, you need to specify the context: Orthogonal filtering or Elliptical Weighted Averaging filtering?

If it is orthogonal filtering, start a new thread ;-)

Re: proper scaling of the Jinc filter for EWA use

Posted: 2011-12-20T02:30:26-07:00
by imaggie
Thanks for your replies.

I'm looking into removing defocus blurring. So, no it's not orthogonal. The application is different but it seems all the windowing and function discussions will be an exact parallel with the same issues. Hopefully we'll get two for the price of one at the end of the day.

I'm not sure that there a theoretical "right" answer as to the choice of window fn since any window takes the infinite fn away from it's true form in a way that is designed to do so gradually without creating discontinuities in order to avoid it being cropped by the edge of the kernel window.

Unless someone has an objective metric that can be measured and defines an error term that can be minimised it may well be somewhat subjective visual assessment that is needed. In any case, as with much of this, the optimum often depends on the subject matter as much as pure maths.

jinc is the FT of the cylinder but the window fn is not specifically related to, say, the FT of the rectangular image array. So there is no 'right' answer there. Single sinc lobe seems a good choice for orthogonal so a rotation of that would seem a good choice for a circularly symmetric fn like jinc.

There is perhaps a temptation to think a jinc - jinc because of some kind of symmetry logic but I don't see any real justification for that idea.

Using sinc lobe I was able to get small but significant improvement over unwindowed jinc (testing has only been trivial this far.)

My problem was getting a generalised way to match the sinc and jinc zero crossings. It seems that distort has already a method for this so I was wondering how I could exploit this to make a deblurring function.

All these convert options, while very powerful, are rather esoteric and I'm struggling a bit with how to use some of them. Maybe you experts can help.

I've been hacking one of Fred's scripts to add a sinc window on the jinc.

Code: Select all

cy=`convert xc: -format "%[fx:floor(($height+1)/2)]" info:`
cyd=`convert xc: -format "%[fx:sqrt(2)*$cy]" info:`

fxd=`convert xc: -format "%[fx:$amount*pi/$w1]" info:`
flanc=`convert xc: -format "%[fx:2*pi/$cyd]" info:`

     convert -size 1x${cyd} gradient: -rotate 90 \
      -fx "zz=($fxd*i); lz=((i)!=0)?i*$flanc:0.000001;  \
           ( (zz<=3) ? ( $jinc1 *sin(lz)/lz)  : (abs(lz)<pi)  * $jinc2 *sin(lz)/lz ) " \
      $tmpL

    convert \( -size ${w1d}x${h1d} radial-gradient: -negate \
      -gravity center -crop ${w1}x${h1}+0+0 +repage \) \
      $tmpL -clut $tmpF
Defining $flanc on the window size is not correct, it needs to be based on the zero point of jinc.

It occurred to me that I could probably use the buildin -distort , jinc and lobe options to do all this much more concisely and correctly but I admit I can't see how.

Any suggestions?

TIA.