Page 1 of 4

High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T04:38:31-07:00
by Akira
Hello devs,
Is there any plan to add high tap (lobe) count Spline filters and the EWA version of them?
Spline filter I refer here is the one you can find in mpv (Spline36/64) or you can use with ffmpeg's -vf zscale.
I think a typical result of spline36/64 resizing is as sharp as Lanczos and has less ringing and halo artifacts.

Here's an example script for spline36 resizing in the linear space using IM and ffmpeg's -vf zscale.
(you need "zimg" library and --with-zimg configured build of ffmpeg to use "zscale" filter: https://github.com/sekrit-twc/zimg)

Code: Select all

new_width="500"
new_height="-1"
filter="f=spline36:r=1:p=unspecified:t=linear:m=unspecified:rin=full:pin=unspecified:tin=linear:min=unspecified:agamma=0"

convert in.png -colorspace RGB -set colorspace sRGB -depth 16 ppm:- | \
ffmpeg -i - -vf zscale=$new_width:$new_height:$filter -f image2pipe -vcodec ppm - | \
convert - -set colorspace RGB -colorspace sRGB -depth 8 out.png

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T11:22:16-07:00
by fmw42
Do you have a reference to the formula for the filter vs number of taps?

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T13:57:06-07:00
by Akira
Yes, for 2-8 taps (16-256 samples), although the page is written in Japanese.
http://www.geocities.jp/w_bean17/spline.html

Google translated version:
https://translate.googleusercontent.com ... PzkdHyDTEw

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T14:11:12-07:00
by fmw42
You can use the window support define in Imagemagick to get more lobes (longer support) in the lanczos filter for example, which may correspond to more taps. I am not an expert. But see
http://www.imagemagick.org/Usage/filter/#lobes
http://www.imagemagick.org/Usage/filter/#support

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T14:28:51-07:00
by Akira
I know that (and spline w/ custom defined lobe count is exactly what I want to use on IM), but the result I get is full of ringings and halos if I use high lobe count Lanczos (2-lobed one is the safest IMHO). When I resize an image on IM, I rather use -distort resize with the default Robidoux filter (as sharp as 2/3 lobed Lanczos & less artifacts).

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T15:16:39-07:00
by fmw42
Do you have any comparisons of the tap filter vs what you feel is the best that Imagemagick can do that shows it is superior? If you have any tests, please provide them.

If you want sharpness, try the cartrom or Lagrange filters (at the expense of other artifacts).

Is the tap filter useful for both shrinking and enlarging or is it best for only one? Is it limited to integer factors?

Do you really need all the very high tap count filters? Don't you find diminishing returns? At what tap count do you find quality vs time cost levels off?

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-13T22:51:27-07:00
by Akira
fmw42 wrote: 2017-08-13T15:16:39-07:00Do you have any comparisons of the tap filter vs what you feel is the best that Imagemagick can do that shows it is superior? If you have any tests, please provide them.
Here's the kernel comparison:
http://svn.int64.org/viewvc/int64/resam ... rnels.html

The difference is subtle. Lanczos is a bit more sharp, but produces artifacts a bit more. I'll probably post some comparison pictures later (rose, LOGO, WIZARD, etc.).
fmw42 wrote: 2017-08-13T15:16:39-07:00Is the tap filter useful for both shrinking and enlarging or is it best for only one? Is it limited to integer factors?
It's fine for both shrinking and upscaling and it works with any factor (EDIT: I meant it's not limited to integer), although EWA filters are better than the tensor Spline36 for upscaling.
fmw42 wrote: 2017-08-13T15:16:39-07:00Do you really need all the very high tap count filters? Don't you find diminishing returns? At what tap count do you find quality vs time cost levels off?
I guess the 3-lobed one is the most balanced for quality vs time, and processing cost wise, it should be identical to Lanczos3.

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-14T09:16:11-07:00
by fmw42
Thanks for the graphs. Nice work.
I guess the 3-lobed one is the most balanced for quality vs time, and processing cost wise, it should be identical to Lanczos3.
I meant in terms of tap count? Do you have a plot of processing time vs "quality" for each tap count you list in your title.

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-14T10:20:34-07:00
by Akira
Whoops, the graphs aren't my work (it's not my page).

The term tap was inappropriate actually. I meant lobes.
Number of lobes vs number of reference samples is the same as Lanczos: (2n)^2 [n=lobes]
2-lobed Spline = Spline16: (2*2)^2=16
3-lobed Spline = Spline36: (2*3)^2=36
4-lobed Spline = Spline64: (2*4)^2=64
...

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-14T18:45:30-07:00
by fmw42
So are you saying your can get what you need from -define filter:lobes={integer}".

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-14T23:52:32-07:00
by Akira
Yes! (if implemented)

But I guess the current Spline filter available in IM is B-Spline, and I don't know if it makes sense to have B-Spline, Spline and Lanczos in a single software.

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-15T04:18:53-07:00
by magick
We added support for Spline 16, 36, and 64 to ImageMagick 7.0.6-8 beta. For example,

Code: Select all

convert logo: -filter spline64 -resize 150x logo_spline.png
The update will be available by sometime tomorrow.

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-15T04:55:28-07:00
by Akira
Thanks! :D

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-15T09:54:06-07:00
by fmw42
I have tested the following minimizing tests in IM 7.0.6.8beta and visually see no difference. A compare does show minor differences of the order of about 0.8% or less with respect to lanczos. But I cannot tell if the spline filters are better or worse.

Code: Select all

magick logo: -filter spline16 -resize 150x logo_spline16.png
magick logo: -filter spline36 -resize 150x logo_spline36.png
magick logo: -filter spline64 -resize 150x logo_spline64.png
magick logo: -filter lanczos -resize 150x logo_lanczos.png
Image

Image

Image

Image

Code: Select all

magick compare -metric rmse logo_lanczos.png logo_spline16.png null:
524.952 (0.00801025)

magick compare -metric rmse logo_lanczos.png logo_spline36.png null:
162.101 (0.0024735)

magick compare -metric rmse logo_lanczos.png logo_spline64.png null:
524.952 (0.00801025)
Oddly the spline36 matches closer to lanczos than the other two, which seem to be identical in their compare values.

Code: Select all

im7beta magick compare -metric rmse logo_spline64.png logo_spline16.png null:
0 (0)
So does this mean that there is a bug in the code or that spline16 and spline64 are no different?

Re: High tap count Spline filters? (Spline36/64/100/144/196/256)

Posted: 2017-08-15T10:09:12-07:00
by magick
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

Add -define filter:verbose=true. Let us know if we implemented the filter correctly.