BC-splines with 2C+B=1 are optimal for EWA resampling
Posted: 2011-11-13T13:26:15-07:00
BC-splines with 2C+B=1 are sometime called "Keys filters" (http://www.imagemagick.org/Usage/resize/#filter_cubics). We'll use this terminology in this thread.
Suppose that one decides to do EWA (Elliptical Weighted Averaging) resampling using a cubic Hermite kernel with breaks at the integers.
Suppose, in addition, that one requires the kernel to have the following properties:
(1) It is continuous.
(2) Its derivative is continuous. ((1) and (2) together mean that the kernel is C^1.)
(3) It is even.
An even piecewise cubic with support [-2,2] is defined by 8 parameters. Condition (1) gives two conditions (left = right at x=1 and at x+2). Condition (2) adds three conditions (left derivative = right derivative at x=0, x=1 and x=2). So, the family is defined by 8-5 = 3 parameters. If, in addition, one does not care what value is taken at x=0 (provided it's not equal to zero), this leaves 2 parameters, often called B and C.
Suppose now that one wants to minimize the resampling error when the data is affine.
It is "common knowledge" that if one is "interpolating" in the usual, tensor, way, the resampling error is 0 if and only if the piecewise cubics are actually the BC-splines with 2C+B = 1 (http://www.cg.tuwien.ac.at/~theussl/DA/node11.html).
What is not common knowledge is the following (I am actually guessing that it is new), which came as a surprise to me:
If you are using even C^1 piecewise cubics with breaks at the integers and support [-2,2] as kernels for EWA resampling, and you want to minimize the resampling error when the data is univariate and affine (that is, the data is of the form a + b*x or a + b*y), then the same Keys piecewise cubics are, once again, the best ones. In that case, the error is not zero (unless b=0) for any choice of parameters (it can't). But the error for BC-splines with 2C+B=1 is smaller than for the nearby piecewise cubic splines satisfying (1)-(3).
Specifically, if one normalizes a piecewise cubic kernel satisfying (1)-(3) so that it's value at the origin is 1 (we can always normalize to any non-zero value when a kernel is used to filter), then the optimal kernels are defined by the relation: (value at 1) + (value of the slope at 1) = -1/2. This last relationship is basically equivalent to 2C+B=1.
(If I have time, I'll explain how I got this result: It's through careful numerical experiments based on proper simplification of the problem.)
Moral of the story:
Suppose that one decides to do EWA (Elliptical Weighted Averaging) resampling using a cubic Hermite kernel with breaks at the integers.
Suppose, in addition, that one requires the kernel to have the following properties:
(1) It is continuous.
(2) Its derivative is continuous. ((1) and (2) together mean that the kernel is C^1.)
(3) It is even.
An even piecewise cubic with support [-2,2] is defined by 8 parameters. Condition (1) gives two conditions (left = right at x=1 and at x+2). Condition (2) adds three conditions (left derivative = right derivative at x=0, x=1 and x=2). So, the family is defined by 8-5 = 3 parameters. If, in addition, one does not care what value is taken at x=0 (provided it's not equal to zero), this leaves 2 parameters, often called B and C.
Suppose now that one wants to minimize the resampling error when the data is affine.
It is "common knowledge" that if one is "interpolating" in the usual, tensor, way, the resampling error is 0 if and only if the piecewise cubics are actually the BC-splines with 2C+B = 1 (http://www.cg.tuwien.ac.at/~theussl/DA/node11.html).
What is not common knowledge is the following (I am actually guessing that it is new), which came as a surprise to me:
If you are using even C^1 piecewise cubics with breaks at the integers and support [-2,2] as kernels for EWA resampling, and you want to minimize the resampling error when the data is univariate and affine (that is, the data is of the form a + b*x or a + b*y), then the same Keys piecewise cubics are, once again, the best ones. In that case, the error is not zero (unless b=0) for any choice of parameters (it can't). But the error for BC-splines with 2C+B=1 is smaller than for the nearby piecewise cubic splines satisfying (1)-(3).
Specifically, if one normalizes a piecewise cubic kernel satisfying (1)-(3) so that it's value at the origin is 1 (we can always normalize to any non-zero value when a kernel is used to filter), then the optimal kernels are defined by the relation: (value at 1) + (value of the slope at 1) = -1/2. This last relationship is basically equivalent to 2C+B=1.
(If I have time, I'll explain how I got this result: It's through careful numerical experiments based on proper simplification of the problem.)
Moral of the story:
The current ImageMagick EWA default, the Robidoux filter, is one such cubic kernel. When I formulated the Robidoux filter, I made a quick and dirty guess that using a BC-spline with 2C+B=1 would be good (because "best" as an orthogonal interpolator should give something at least OK as an EWA kernel), with the intent of changing the parameters when I have time to tune it better. I had no idea that actually the Keys filters were actually truly, not only approximately, optimal in terms of exactness on linears a.k.a. second order accuracy, and consequently I optimized the right family (with respect to preservation of constant on rows/columns data under no-op).If you are going to upsample or resample with a piecewise cubic kernel with breaks at the integers and support [-2,2], used as an EWA (Elliptical Weighted Averaging) filter weight, use a BC-spline with 2C+B=1. (If downsampling, I don't know.)