bamupsampler

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

bamupsampler

Post by BryantMoore »

I think I might have a decent scheme for upsampling.

Original
Image

Bilinear
Image

Code: Select all

convert floor.jpg +filter -resize 400% triangle2.png
Bamupsampler
Image

Code: Select all

convert floor.jpg -colorspace rgb +sigmoidal-contrast 8 -define filter:blur=1 -define filter:support=4 -define filter:win-support=4 -define filter:window=bessel -define filter:filter=bessel -distort resize 400% -sigmoidal-contrast 8 -colorspace srgb bamsampler2.png
Let me know what y'all think. :)
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: bamupsampler

Post by BryantMoore »

I've developed the filter into something I like to call Kaissel (kaiser windowed bessel).

rose-triangle.png
Image

Code: Select all

convert rose: -filter triangle -resize 2000% rose-triangle.png
rose-mitchell.png
Image

Code: Select all

convert rose: -filter mitchell -resize 2000% rose-mitchell.png
rose-kaissel.png
Image

Code: Select all

convert rose: -colorspace rgb +sigmoidal-contrast 8 -define filter:blur=1 -define filter:support=4 -define filter:win-support=4 -define filter:kaiser-beta=1 -define filter:window=kaiser -define filter:filter=bessel -distort resize 2000% -sigmoidal-contrast 8 -colorspace srgb rose-kaissel.png
Awaiting input. :D
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: bamupsampler

Post by BryantMoore »

Kaissel seems to work very well as a downsampler with a little blur.

Image

Code: Select all

convert fly.jpg -colorspace rgb +sigmoidal-contrast 8 -define filter:blur=1.25 -define filter:support=4 -define filter:win-support=4 -define filter:kaiser-beta=1 -define filter:window=kaiser -define filter:filter=bessel -distort resize 403 -sigmoidal-contrast 8 -colorspace srgb fly-kaisseldown.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bamupsampler

Post by anthony »

This is what the filter (filter:vebose=1) generates..
# filter = Jinc
# window = Kaiser
# support = 4
# window-support = 4
# scale-blur = 1.25
# kaiser-beta = 1
# practical-support = 5

NOTES
  • The filter 'bessel' just means jinc. It is the old name for that function (from the Paul Heckbert's "zoom" program), and only kept for backward compatibility. It does not appear on the -list filter output. Use Jinc instead.
  • Then as -distort resize is used and you supply a windowing function, jinc would automatically be selected.
  • As win-support is the same as support you don't need to specify it.
  • Finally support will be blurred by the blur factor, so actual working support is 4*1.25 or 5 and you are not picking a zero crossing for the jinc support, though the windowing function should handle it, it is typically not done.

    As such your direct support request is really just adjusting the fit of the windowing function fall off to the jinc weighting function, while blur is adjusting the zero crossings to strange positions.
Here is the cleaned version...

Code: Select all

 convert fly.jpg -colorspace rgb +sigmoidal-contrast 8 -define filter:blur=1.25 -define filter:support=4  -define filter:kaiser-beta=1 -define filter:window=kaiser -distort resize 403 -sigmoidal-contrast 8 -colorspace srgb fly-kaisseldown.png
filter:verbose=1 output

Code: Select all

# filter = Jinc
# window = Kaiser
# support = 4
# window-support = 4
# scale-blur = 1.25
# kaiser-beta = 1
# practical-support = 5
Its graph is unusual,
Image
especially for the near NO-OP case. Closest orthogonal neighbours are heavily averaged, but orthogonal neighbours 2 units distant is maximumly negative. Diagonal neighbours have a near zero contribution.

As a down-samplier, on the fly, it seems to work producing a very different style of moire in the eyes (and different moire at that). It makes me think that it is probably 'blocking/aliasing' moire rather than 'sharpening/ringing' moire.

Now what is behind the decisions for the weird non-typical filter settings you have selected?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: bamupsampler

Post by BryantMoore »

anthony wrote:Now what is behind the decisions for the weird non-typical filter settings you have selected?
It looks good to my eyes. :)
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: bamupsampler

Post by NicolasRobidoux »

Bryant:
People do find "good new things" by breaking rules.
So, I think you should know some of the "rules" that I use when developing filters for "general use".
Every single filter recommended in http://www.imagemagick.org/Usage/resize/#nicolas is (pardon my math) C^0, that is, the filter is continuous. In particular, there is no jump at the limit of the window.
The reason for this is that, esp. when enlarging, jumps (at the limit of the window or elsewhere) will lead to very strong artifacts.
Actually, only two of the recommended filters are not C^1 (continuous with continuous gradient): EWA and tensor Triangle are the two exceptions, and they are only recommended for downsampling.
Indeed, if a filter fails to be C^1 (fails "enough"), you will see "ridges" and like artifacts when enlarging.
Two of the recommended ones are C^2 (EWA and tensor Spline).
Sigmoidization does not affect whether a filter is C^n or not.
-----
Although some may say that I am rather picky, I do my best to produce filters that, at all times, are free of avoidable "bad artifacts".
If your image is very smooth with a nicely bell shaped color histogram, small evils are likely to be forgiven.
Unfortunately, Murphy is waiting around the corner with a pitchfork.
In addition, there are evils that can be forgiven when processing an audio signal with a filter that uses lots of data points (with many "taps"). Image resampling filters generally use few points in each direction. Generally no more than about 9 (the number for a typical 4-lobe method) when enlarging, and usually less. So, these small evils (like lack of continuity) generally hurt more in image resampling that in traditional signal processing, esp. when enlarging (since, when reducing, more pixels are grabbed and filtered).
Last edited by NicolasRobidoux on 2012-09-29T10:18:00-07:00, edited 7 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: bamupsampler

Post by NicolasRobidoux »

Turning the fly eyes to rust is evil.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: bamupsampler

Post by NicolasRobidoux »

Bryant:
The image that you show for the rose with the "Kaissel" scheme has nothing to do with the code you show for it. For one thing, it's a 4-band image.
If I use your code, I get something with ugly ridges all over the place, as expected.
What you show looks, to my eye, like the result of sigmoidized LanczosSharp with contrast equal to about 8. And indeed, it's within 4, in max norm, of the output of

Code: Select all

magick rose: -colorspace rgb +sigmoidal-contrast 7.5 -filter LanczosSharp -distort resize 2000% -sigmoidal-contrast 7.5 -colorspace srgb rose-lanczossharp.png
(IM7 compiled in HDRI, not that IM6 in Q16 would make much of a difference).
4 falls short of JND.
For all I know, it could be that you use a slightly out of date version of sigmoidal-contrast, and you used exactly the above code (with convert instead of magick).
Or you used my preferred version of LanczosSharp instead of the built-in one.
Last edited by NicolasRobidoux on 2012-09-29T08:14:02-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: bamupsampler

Post by anthony »

NicolasRobidoux wrote:Actually, only two of the recommended filters are not C^1 (continuous with continuous gradient): EWA and tensor Triangle are the two exceptions, and they are only recommended for downsampling.
Actually the Lagrange is full of discontinuities. The even orders (half integer support) are not even C^0! In fact the triangle filter is actually even on of the largange orders (order 1).

Also I am not saying your filter is 'wrong', as really there are no 'wrong' filters. Just unusual, in the way it places minimum at 2 units from the sample point, and has zero for 4 units. It may be you have discovered something, but I have no idea what.
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: bamupsampler

Post by NicolasRobidoux »

@Anthony:
I do not recommend Lagrange.
I suppose I should have made clearer that I was expressing my own personal opinions.
P.S. @Anthony: All clear.
Last edited by NicolasRobidoux on 2012-09-28T19:17:57-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bamupsampler

Post by anthony »

NicolasRobidoux wrote:@Anthony:
I do not recommend Lagrange.
I suppose I should have made clearer that I was expressing my own personal opinions.
Nor do I... See the edit update in previous post.
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: bamupsampler

Post by fmw42 »

For maximum sharpness without regard to artifacts when upscaling, I like EWA Lagrange and EWA Catrom.
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: bamupsampler

Post by BryantMoore »

I have a lot to learn. :D
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: bamupsampler

Post by NicolasRobidoux »

fmw42 wrote:For maximum sharpness without regard to artifacts when upscaling, I like EWA Lagrange and EWA Catrom.
Yes, and Henry likes EWA Lagrange for downsampling when USM would be appropriate.
When I have some time, I'll have to figure out what's going on. And I'll have to carefully test it myself.
At this point, I can't imagine that it would be better than EWA Box-windowed Sinc or Jinc with the right number of lobes.
But it takes me time to understand what underlies good and bad properties.
P.S. Fred: I know I'm biased against Lagrange, because it makes little sense to me in the image filtering context, and because there is a theorem that makes clear that they don't even approximate analytic functions well on a uniform grid, when the degree is high (the Runge phenomenon). And images are generally pretty far from being analytic, analytic functions being the easiest one to approximate well. (Well, not quite: entire functions like the exponential and Sine and Cosine are easier.)
But then, the Keys cubics working well with EWA made no sense until I computed that they reproduce affine functions best among all BC-splines. So, what do I know?
Last edited by NicolasRobidoux on 2012-10-01T06:33:21-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bamupsampler

Post by anthony »

Hey... until Nicholas help fix the EWA code, and cause me to find the 'sign bug' in the calculations that caused the old excessive blurring, We probably would still be using gaussian as a EWA filter! Now EWA is more often than not better than 2-pass orthogonal resize (tensor), without too much slowness either.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply