Log in

View Full Version : Helping with image function


luquinhas0021
8th August 2015, 13:30
How can I find a function z = f(x,y) that passes through the k x p (Same thing of image resolution) values of an image (Values of one component: r, g or b; Y, Cb or Cr), and have a continuus and pretty accurate first, second and third partial derivates and full derivates?
If isn't possible discover a function for all k x p image points, is possible find a function for a block of a x a points? a x a is included in k x p.
I asked it because all polynomial interpolation methods generates a so expensive order polynoms, and, it seems, doesn't have continuus and pretty accurate derivates.

colours
8th August 2015, 18:51
I'm going to assume that you're once again asking about things that sounded ideal in your head but you didn't bother working out any of the details. Maybe you should.

If your image comes with partial derivative information (which is impossible), then yeah, you'd have to do a polynomial interpolation over the whole image. Which, apart from being slow to evaluate, also sounds like a totally wrong thing to do anyway because of Runge's phenomenon (https://en.wikipedia.org/wiki/Runge's_phenomenon). It's possible to do some fancy stuff with bump functions to avoid this while remaining infinitely differentiable, but using bump functions is cheating so we don't do that.

Otherwise, in the one-dimensional case, if you want continuous derivatives of arbitrarily high order, you can use B-spline interpolation. (This is Θ(n) arithmetic operations per output pixel if you want continuous nth derivatives.) For more dimensions, just interpolate in each dimension separately and you'll get your continuous partial derivatives. Quartic and quintic B-spline interpolation give continuous derivatives up to the fourth order (but not the fifth), which sounds a bit like what you're asking for.

wonkey_monkey
8th August 2015, 19:35
How can I find a function z = f(x,y) that passes through the k x p (Same thing of image resolution) values of an image (Values of one component: r, g or b; Y, Cb or Cr), and have a continuus and pretty accurate first, second and third partial derivates and full derivates?

I may be wrong, but aren't there an infinite number of functions that can pass through any particular set of points? So how would you know which one was "accurate"? They'd all be "correct."

LoRd_MuldeR
9th August 2015, 13:52
I may be wrong, but aren't there an infinite number of functions that can pass through any particular set of points? So how would you know which one was "accurate"? They'd all be "correct."

Yes, in general, there is an infinite number of functions that can pass through any particular set of points. But you can define some constraints in order to get a "smooth" and "natural-looking" (and unambiguous) curve.

For example, Cubic Splines are commonly used to create a function that passes through a particular set of points and that comes out "smooth".

The Cubic Spline is constructed, piecewise, of third-order polynomials. For each sub-interval, the current third-order polynomial has to go through the "starting" point and the "ending" point. That alone, would allow for an infinite number of solutions. But there is the additional constraint: At the "junction points", the first- and second-order derivatives of the "neighboring" polynomials have to be equal. This way, we get a smooth transition - rather than a "kink" - at the junction points.

Given these constraints, there is only one solution for any given set of points... :)

luquinhas0021
11th August 2015, 06:00
I don't like b-spline because it causes excessive smoothness.
After research over and over, I found the Hermite spline and the Clamped spline. In all sites is said that Clamped Spline has better accuracy than Natural Cubic spline, given same function and same dots. But the unique site that compares Hermite Cubic spline and Natural Cubic spline says that, given a same function and same dots, Hermite Cubic spline is more accurate. In image is no different: in fact, Hermite Cubic spline based resizer (Spline 144) gives a sharper and more detailed result than Natural Cubic spline based resizer (Spline 36. The results of it are compared with bicubic -0.001, 0.505). So, does someone know say to me if Clamped spline is more accurate than Hermite splines, given the same function and same dots, be an image or other data?
Increase the spline polynomial degree improves it accuracy, given same type of spline, such Hermite spline (Like make quintic Hermitespline)?
By the way, highest order spline, such sextic, septic, octic, nontic, tenth, eleventh, twelft and thirteenthhas continuum first, second and third derivatives?
Please, who knows, reply me.

feisty2
11th August 2015, 06:32
spline144 (aka 6tap spline), I'll take what you mean "accurate" by "more taps", well, 6 taps ain't no the biggest, try "taps=128" and welcome to the big bright world of "ringing"
https://en.wikipedia.org/wiki/Ringing_artifacts

foxyshadis
11th August 2015, 11:24
spline144 (aka 6tap spline), I'll take what you mean "accurate" by "more taps", well, 6 taps ain't no the biggest, try "taps=128" and welcome to the big bright world of "ringing"
https://en.wikipedia.org/wiki/Ringing_artifacts

Great. Now there's going to be a new "How to make spline65536 using nnedi3" thread tomorrow.

luquinhas0021
11th August 2015, 11:26
You're so funny, Feisty! I like Spline 144 'cause it retain much detail, more than others, and has less aliasing and less ringing than bicubic -0.001, 0.505; and is fast! Good algorithm, not?! But I'm worried about upscaling bigger than 2x, hence spline 144, although has little artifacts, even has it.
If you know about questions I did today, please, answer me!

colours
11th August 2015, 19:16
I don't like b-spline because it causes excessive smoothness.

lol no

Read this. (http://www.ipol.im/pub/art/2011/g_lmii/) And the articles it cites. Or at the very least, LoRd_MuldeR's post above if you can't handle all the ~mathematics~.

Hermite Cubic spline based resizer (Spline 144) […] Natural Cubic spline based resizer (Spline 36

lol no

By the way, highest order spline, such sextic, septic, octic, nontic, tenth, eleventh, twelft and thirteenthhas continuum first, second and third derivatives?
Please, who knows, reply me.

I somehow was psychic enough to have answered this question before you even posted it. If you can't read English, maybe you should go learn that before trying to do research in a field where most of the literature is in, guess what, English.

luquinhas0021
15th August 2015, 14:31
According I see, at least Cubic B-spline image upscaling gives so smoother results, when compared with Bicubic. Maybe Bicubic B-spline gives sharper results.
Sure, Colours? In Spline resizer Avisynth documentation (Is that we see in External Filters, in Avisynth Wiki) tell us the same thing I spoke: Avisynth Spline internal resizers (Spline 16, Spline 36 and Spline 64), are based in Natural Cubic Spline. The other (External Spline resizers) are based in Cubic Splines, which is the same of Hermite Cubic Spline.
Yes, I understand English: read, write, listen and speak.

colours
15th August 2015, 16:56
In Spline resizer Avisynth documentation (Is that we see in External Filters, in Avisynth Wiki) tell us the same thing I spoke: Avisynth Spline internal resizers (Spline 16, Spline 36 and Spline 64), are based in Natural Cubic Spline. The other (External Spline resizers) are based in Cubic Splines, which is the same of Hermite Cubic Spline.

So, for the first time, because I almost thought I was wrong on the internet (truly an embarrassing plight to be in), I carefully went through Wilbert's description (http://forum.doom9.org/showthread.php?t=147117) of Panorama Tools' "Spline" resampling kernels. Very carefully.

The kernels are defined piecewise. Within the interval [−n,n], it is defined as the natural cubic spline passing through the 2n+1 knots (0,1), (±1,0), (±2,0), …, (±n,0); outside [−n,n], it is defined to be 0. (n is the parameter corresponding to the number of taps on one side; i.e. n = 2 ⇒ Spline16; n = 3 ⇒ Spline36; etc.) The resulting kernel is not everywhere continuously differentiable, as the derivative has a jump discontinuity at ±n. As n tends to infinity, the kernels converge (uniformly) to the cubic B-spline interpolation kernel, so you might as well just use that directly. Going by the operation count, which is totally (not) a valid way of estimating algorithm speed, cubic B-spline interpolation should be about as fast as Spline64.

(Fun fact: swscale's "spline" kernel is also a cubic spline passing through those same knots, but without boundary conditions set. Instead, the function is defined to be equal to the cubic B-spline interpolation kernel over [0,1], and then extrapolated to [1,2], [2,3], [3,4], and so on. (Each such segment [k,k+1] is given by a cubic function, which has four coefficients. The four equations to solve these coefficients come from f(k) = 0, f(k+1) = 0, the continuity of f' at k, and the continuity of f'' at k.) This converges to the cubic B-spline interpolation kernel, modulo numerical stability issues because the associated linear map has an eigenvalue greater than 1.)

At any rate, just because the kernel was derived as a natural cubic spline doesn't mean that convolving with it is equivalent to natural cubic spline interpolation. Natural cubic spline interpolation is exactly the same as cubic B-spline interpolation with a specific set of boundary conditions. The cubic B-spline interpolation kernel has infinite support and is twice continuously differentiable, both of which are evidently untrue for Panorama's spline kernels.

Hermite splines are a different thing, and only force continuity of the first derivative, not the second. They're not related to Panorama's Spline kernels, and I have no idea where you even read anything making any claim otherwise.

If you want quintic Hermite splines, I suggest looking up what Hermite interpolation is and making the obvious conclusion.

Tl;dr: So yeah, you were technically correct to say Spline36 and Spline64 were based on natural cubic splines, but merely being "based on" doesn't mean much. You were also wrong in claiming that Spline144 was related to Hermite splines, so there.

PS: If you want cubic B-spline interpolation in AviSynth, you can use debilinear or debicubic for the prefiltering step. I'm not going to spoonfeed how to do this because (i) I shouldn't have to do all your work for you and (ii) I'm actually just really lazy.

wonkey_monkey
15th August 2015, 19:32
I just subjected the spline resizers to a test - applying 256 rounds of down/upscaling with each resizer. Here are the results:

http://horman.net/avisynth/splines.png

In order:
Original
spline16resize
spline36resize
spline64resize

Is there something wrong with spline36resize? See how it darkens the interior of the white curves in the top left, which the other two don't do.

luquinhas0021
16th August 2015, 00:11
Colours, I was wrong when I said B-spline generates a smoothest results. Thank for this correction, for anothers and for every other things you teach me.

*.mp4 guy
23rd August 2015, 05:53
Is there something wrong with spline36resize? See how it darkens the interior of the white curves in the top left, which the other two don't do.There is nothing wrong with spline36, the artifact you are seeing is called "being a linear interpolator with a third lobe (aka tap)" spline 64 also has the same problem if you look (very) closely, it is just obscured by the heaping amount of blur that the spline64 kernel has compared to spline36.