Showing cardinal basis functions (resampling an impulse)

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?".
Post Reply
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

Suggestion: When showing cardinal basis functions, that is, what happens to an impulse (e.g. http://www.imagemagick.org/Usage/resize ... catrom.jpg), it is my opinion that it is better to use light gray instead of white as "foreground", and dark gray instead of black as "background", because then you will be able to see "ripples" which are clipped when using white and black.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

Actually, because reasonable filters only undershoot when resampling an impulse, it's enough to change black to (dark) gray.

P.S. ... reasonable filters SHOULD overshoot very little when resampling an impulse... See below!
Last edited by NicolasRobidoux on 2012-04-23T05:15:43-07:00, edited 2 times in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Showing cardinal basis functions (resampling an impulse)

Post by anthony »

This is true. But at the time I was trying to showing more the difference in basic interpolation filter results between resize and distort filter rather than exact result of the filter.

However I'll re-work that examples to use gray values instead of black and white.

Technically I should also be converting from a linear RGB case to sRGB too :-)

The Examples for those joining this discussion are actually located at the end of...
http://www.imagemagick.org/Usage/resize ... terpolated
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: Showing cardinal basis functions (resampling an impulse)

Post by anthony »

Well it seems that the 'ringing' effects show a much more marked difference between the use of equivelent resize and distort interpolation! Distort of course is more circular, but can also be more pronounced!


When these images appear the examples have been updated (give it an hour or so)
Image Image
Resize (tensor) Catrom vs Distort (EWA) Catrom Filtering
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: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

So I missed that in principle "reasonable" EWA filters could sharpen an impulse. A lot. Makes complete sense, and I "knew" it, but it's funny how seeing it makes you know it for real.

(Thank you. It's nice to "see" things.)
Last edited by NicolasRobidoux on 2012-04-23T05:17:55-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: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

If there was any need for proof that RobidouxSharp is pretty much as far as one should push a Keys cubic toward Catmull-Rom when using it as an EWA weight function...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Showing cardinal basis functions (resampling an impulse)

Post by anthony »

Cubic Keys Filters (named) in ImageMagick from very blurry cubic B=1.0 C=0.0 to sharp catrom B=0.0 C=0.5
generated using EWA distort to resize the result

Code: Select all

convert xc:gray80  -bordercolor gray20 -border 2 \
            -filter $filter   +distort SRT 20,0  dot_distort_$filter.png
Image cubic
Image robidoux
Image mitchell
Image robidoux_sharp
Image catrom

Note the three in the middle are quite close together in relation to the ones on the end.

Note while catrom is oversharp with a deep 'trough-like halo' surrounding it, none of them actually have 'ringing' effects

To complete the named Cubics... Hermite is a sharp cubic but without a trough. B=0.0 C=0.0
Image hermite
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: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

anthony wrote:...
Note the three in the middle are quite close together in relation to the ones on the end.
...
And yet henriwho saw a very clear difference when downsampling between Robidoux (too blurry, in his opinion) and RobidouxSharp (too aliased).

Given how many pixels are touched by an EWA in comparison with a tensor implementation of the same "filter", it makes sense that small differences in filter values matter more with EWA.
Last edited by NicolasRobidoux on 2012-04-24T03:58: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: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

Hermite clearly has a "fat x watermark".
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Showing cardinal basis functions (resampling an impulse)

Post by anthony »

NicolasRobidoux wrote:Hermite clearly has a "fat x watermark".
that 'watermark' is a reflection of the change in blending. It is an echo of the 'X' you get in a EWA box filter.
Image

You also see it in the filter between box and hermite.... triangle. Though there it is more of a '+' than and 'x' due to the larger support (discontinuity of slope)
Image

It is also visible in Lagrange, where it is caused by the slope discontinuity that that interpolation filter produces. Lagrange filter can also generate box, triangle filters too by adjusting its 'order' via the filters support size.
Image

Lagrange Interpolation Filters graph..
Image

See IM Examples, Other Interpolation Filters
http://www.imagemagick.org/Usage/resize ... late_other
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: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

anthony wrote:
NicolasRobidoux wrote:Hermite clearly has a "fat x watermark".
I was not writing that there was a bug/error. I was observing that Hermite shows a really bad artifact right in the cardinal basis function plot. Like many others. But not, interestingly enough, the Keys cubics.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Showing cardinal basis functions (resampling an impulse)

Post by anthony »

Oh... Thats is because they have such a smooth curve, that you don't see the effect of pixels entering and leaving the support 'circle' (ellipse).

Look at 'support' which shows clearing this type of support generated artefact (internal and external) with a odd support window on a gaussian filter
http://www.imagemagick.org/Usage/resize/#filter_support

In orthogonal filtering such artefacts are rarely visible as any integer or half-integer support will ensure for every pixel that enters the support window, a pixel is also leaving (except at edges)
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: Showing cardinal basis functions (resampling an impulse)

Post by NicolasRobidoux »

anthony wrote:
NicolasRobidoux wrote:Hermite clearly has a "fat x watermark".
...
that 'watermark' is a reflection of the change in blending. It is an echo of the 'X' you get in a EWA box filter.
...
You also see it in the filter between box and hermite.... triangle. Though there it is more of a '+' than and 'x' due to the larger support (discontinuity of slope)
...
(Probably a bad) idea: Blend EWA Triangle and EWA Hermite so as to minimize deviation from rotational symmetry, and consequently use the "+" to erase the "x", and vice versa. Or minimize the affine gradient reconstruction error.
This may get a halfway reasonable interpolatory EWA filter, with a really tight stencil.
Manana.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Showing cardinal basis functions (re 'Pasampling an impu

Post by anthony »

Not sure it is worth looking at.

However you can generate many new interpolating filters by using box with a support of 1.0, but then apply various Sinc windowing functions to that to 'shape' the box. You need to do it this way as only windowing functions are scaled to match the filters support.

I use this 'windowed box' technique to scale and extract the actual window function for graphing. See "filter:verbose" expert option notes. For example here I get the plot data of the 'Welsh windowing function'. This would produce a parabolic interpolation filter!

Code: Select all

  convert null: -define filter:filter=Box \
                   -define filter:window=Welsh \
                   -define filter:support=1.0 \
                   -define filter:verbose=1 \
              -resize 2 null:  > window_welsh.dat
  gnuplot
     set grid
     plot [0:1][0:1] "window_welsh.dat" with lines
And here I test it.

Code: Select all

convert xc:gray80  -bordercolor gray20 -border 2 \
    -define filter:filter=Box -define filter:window=Welsh -define filter:support=1.0 \
    +distort SRT 20,0  dot_distort_parabolic.png
And here is the image (which is slightly different but almost identify to hermite.
Image
This means it is the 'sharp peak' that causes the Triangle 'x' artefacts.

Another unexpected result in my own tests is the use of a Gaussian with a small sigma (sigma=1/3 - my Gaussian interpolation)
Image
As you can see a small gaussian sigma produces 'squarish' results as a cylindrical filter! Which as it remains 'separable' should produce the same result for resize. It may be why I like gaussian interpolators for some things :-)

PS: you get similar results for a 'Parzen' (window scaled Cubic) window filter, using the same technique as the 'welsh - parabolic' interpolation filter above.

This sort of thing is actually why I added an expert settings to just about every control I could think of, when I re-developed resampling filters. For example I not only have a way to specify the normal support limits of the main weighting function, but then allow you to specify a different 'window_support' to the windowing function. It allows you to 'mix and match' how the two functions get 'multiplied together' to generate a whole array of filter curves to use, using just what has been implemented!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply