Monotonic Cubic Spline Interpolation
Monotonic Cubic Spline Interpolation
George Wolberg
Itzik Alfy
Department of Computer Science
City College of New York / CUNY
New York, NY 10031
wolberg@cs-mail.engr.ccny.cuny.edu
f (x)
f4 f5 g
1 INTRODUCTION f3 g g
f2 g
Cubic splines are widely used to fit a smooth continu- f0 f1
ous function through discrete data. They play an important g g
role in such fields as computer graphics and image process-
x
ing, where smooth interpolation is essential in modeling, xg0 x1 x2 x3 x4 x5 x6
animation, and image scaling. In computer graphics, for
instance, interpolating cubic splines are often used to define Figure 1. Cubic spline.
the smooth motion of objects and cameras passing through
user-specified positions in a keyframe animation system. The goal of this work is to derive the smoothest possible
In image processing, splines prove useful in implementing cubic spline that simultaneously interpolates the data and
high-quality image magnification. satisfies the monotonicity constraint. In cases where the
Cubic splines interpolate (pass through) the data with input is not monotonic, the data can be split into consec-
piecewise cubic polynomials. The use of low-order polyno- utive intervals of monotonically increasing and decreasing
data. For now, though, we shall limit our attention to one [5, 14, 15, 4]. If two extra break points are allowed be-
strictly monotonic interval spanning all the points. We be- tween each data subinterval, then there are enough degrees
gin with a review of the literature in Section 2 and a review of freedom to construct a globally C 2 cubic spline inter-
of cubic spline interpolation in Section 3. The monotonic- polant which is local and which has slopes and curvatures
ity constraint is discussed in Section 4. Optimization-based at the data points as free parameters [15]. Additional break-
solutions are introduced in Section 5. Section 6 presents points, however, require more storage and increased search
examples. Finally, a discussion and summary of the work is time during evaluation [7].
presented in Section 7 and Section 8, respectively.
3 CUBIC SPLINES: A REVIEW
2 PREVIOUS WORK
A cubic spline f (x) interpolating on the partition x0 <
There is a large body of work in the field of monotonic x1 < ::: < xn?1 is a function for which f (xk ) = yk .
cubic spline interpolation. Early work in this area dates back It is a piecewise polynomial function that consists of n ?
to Schweikert’s work on splines in tension, where exponen- 1 cubic polynomials fk defined on the ranges [xk ; xk+1].
tial splines were used as approximants [18]. Various other Furthermore, each fk is joined at xk , for k = 1; :::; n ? 2,
exponential and cubic spline interpolants were considered in such that yk0 = f 0 (xk ) and yk00 = f 00 (xk ) are continuous.
[20, 12, 13, 14, 5]. Tension parameters were used to control An example of a cubic spline passing through n = 7 data
shape. All of these methods were global, interpolatory, and points is illustrated in Fig. 1.
C 2. Automatic algorithms to determine free parameters to The k-th polynomial curve, fk , is defined over the fixed
control shape and monotonicity were complicated. In [11], interval [xk ; xk+1] and has the cubic form
an algorithm was presented to generate shape preserving
curves of arbitrary smoothness based on the properties of fk (x) = ak (x ? xk )3 + bk (x ? xk )2 + ck (x ? xk ) + dk (1)
Bernstein polynomials. However, C 2 smoothness required
the use of piecewise polynomials whose degree exceeded where
?2 ∆∆xyk
three. There is also the possibility of using piecewise ratio-
ak 1
+y
0 +y
0
nal interpolants [6, 9], although these are usually only C 1 or =
∆x2k k k+1 (2a)
k
are intended for strictly monotone or strictly convex data.
∆yk
In 1980, Fritsch and Carlson proposed a two-pass algo- bk =
1
∆xk
3
∆xk
? 2yk0 ? yk0 +1 (2b)
rithm for computing monotone cubic interpolant [7]. In
1984, Fritsch and Butland proposed a modified technique ck = yk0 (2c)
to simplify the 1980 algorithm [8]. In the modified algo- dk = yk (2d)
rithm, the first derivatives at the knots are calculated using
Brodlie’s formula to give the most visually pleasing results. In the expressions for bk and ak , ∆xk = xk+1 ? xk and
The Fritsch and Butland technique is also available ∆yk = yk+1 ? yk , for k = 0; :::; n ? 2.
in Netlib (PCHIM.FOR). This can be downloaded from The expressions for the cubic polynomial coefficients in
www.math.iastate.edu/cmlib/pchipd.html. Eq. (2) are given in terms of position data and derivatives.
Both algorithms are local and yield only C 1 continuous In cases where only position data is supplied, the derivative
curves, even if a global C 2 solution exists. Furthermore, values may be evaluated by solving a tridiagonal system of
there is no flexibility in defining an application’s specific equations that relate the unknown derivatives to the known
properties for the desired spline, e.g., the objective function position data. Derivations can be found in [16] and [21].
or constraints for a given optimization problem. To make the derivatives invariant to scale change, we
In [1, 2, 3], several algorithms were proposed to compute shall find it useful to relate the derivatives in terms of slope
shape preserving splines that are monotone and convex. The mk = ∆yk =∆xk :
algorithms are based on [7] and iteratively compute a set of
first derivatives that simultaneously satisfy the monotonicity yk0 = k mk (3a)
and convexity constraints. y0 k+1 = k mk (3b)
Schumaker [17] proposed a shape preserving interpola-
tion algorithm to produce a C 1 quadratic spline with addi- for k 0 and k 0.
tional knots where necessary. The algorithm is interactive, Although the user-supplied data points are fixed, the
and the user has flexibility in adjusting the shape of the derivatives can be changed to yield a large family of in-
interpolating spline under some relationship rules. terpolating cubic splines. We are interested in determining
Several researchers have investigated other approaches the range of derivative values for which the spline remains
involving the use of additional knots between data points monotonic. To motivate the need for determining this range
2
of derivative values, Fig. 2 shows a set of five cubic curves, (b) k + 2 k ? 3 0
each with derivative yk0 = 0 and increasing values for yk0 +1 . 2k + k (k ? 6) + (k ? 3)2 < 0
In particular, k = 0 and 1 k 5 for integer values of
(c)
k . Tangent vectors are shown for the k = 1 and k = 5 Conditions (1), (2a), (2b), and (2c) are depicted graphi-
cases. Note that the monotonic constraint is violated when cally as regions I , II , III , and IV in Fig. 3(a). The union
k > 3, i.e., a local minima is present in the span. of these regions, shown in Fig. 3(b), is bounded by lines
k = 0, k = 0, and the ellipse. The monotonicity region
βk =5 M in Fig. 3(b) can be expressed as follows:
if 0 k 3
yk +1
g βk =1 0 < k + k < 3 + s
M= 3 ? s < k + k < 3 + s if 3 < k 4 (5)
where
p
s = k k .
All points in region M denote valid
∆ yk
( k ; k ) pairs that preserve monotonicity.
αk αk
yk
gα =0 4 4
k
∆ xk
xk xx +1 3 3
II IV M
2 2
Figure 2. A family of cubic polynomials.
1 1
I
III
4 MONOTONICITY 0 βk 0 βk
0 1 2 3 4 0 1 2 3 4
(a) (b)
In this section, we consider a single cubic polynomial
fk (x) in the interval [xk ; xk+1] and present necessary and Figure 3. (; ) pairs for a monotonic curve.
sufficient conditions for which fk (x) is monotonic in the in-
terval [7]. These conditions form the basis of the monotonic
cubic spline interpolation algorithm. 5 OPTIMIZATION-BASED SOLUTIONS
A curve is monotonic in an interval [xk; xk+1 ] if and only
if there is no sign change in the derivative value along any
In this section, we consider several solutions to the mono-
part of the curve in the interval. Therefore, a necessary
tonic interpolation problem based on optimization tech-
condition for monotonicity is that
niques. We will investigate solutions derived by linear and
sgn(yk0 ) = sgn(yk0 +1 ) = sgn(mk ) (4) quadratic programming techniques subject to various con-
straints on first and second derivative continuity.
Furthermore, if mk = 0, then fk (x) is monotone (constant) The objective criterion for the optimization techniques
in the interval if and only if yk0 = yk0 +1 = 0. will be based on energy measures of the curves. We begin
In the remainder of the presentation, we will assume that with a review of the classic cubic spline energy measure in
mk 6= 0 and that Eq. (4) is satisfied. As a result, fk (x) is Section 5.1. Since the original cubic spline formulation is
strictly monotonic in the interval [xk ; xk+1] if fk0 (x) 6= 0 not guaranteed to be monotonic, we will impose the mono-
for xk x xk+1 . This implies that there are no local tonicity constraint in Section 5.2. This will furnish a solu-
extrema (minima/maxima) in that span. tion that may be solved using quadratic programming. Since
The monotonicity constraints can be summarized by the monotonic cubic splines are not guaranteed to be C 2 contin-
following two lemmas [7]: uous, a new energy measure is introduced in Section 5.4 that
addresses the extent of second derivative discontinuity in the
1) If k + k ? 2 0, then fk (x) is monotone if and only spline. That result is further simplified in Section 5.5 to yield
if Eq. (4) is satisfied. a solution that may be solved using linear programming.
2) If k + 2k ? 2 > 0, then fk (x) is monotone if and
only if Eq. (4) and one of the following conditions is
5.1 Spline Energy
satisfied:
Cubic splines originally arose as a mathematical model
(a) 2k + k ? 3 0 for a draftman’s spline. Cubic splines mimic the position of
3
αk αk
a flexible thin beam that is forced to pass through the given
data points [10, 5]. The strain energy of the beam is given 4 g 4 g g
g
g1413 12 11 g
as the integral of the curvature: 6 5 15 10 g
3 g g 3 g 9 g
E=
Z xn?1
f 00 (x)2 dx 8 g
(1 + [f 0 (x)]2 )5=2
(6) 2 M 4 2 M 7g
x0 1 1 6
1 g 1 g
The elastica is the ideal spline, i.e., the function f (x) that 3 5
2 2 3 g4 g
minimizes Eq. (6). Due to the inherent difficulty in solving 0 g g βk 0 g g βk
for f (x) under this formulation, a simpler linearized energy 0 1 2
(a)
3 4 0 1 2
(b)
3 4
4
C 2 solution domain. Note that the solution for C 0 mono-
tone constraints is the linear interpolation with EL = 0. Method E EL ED
This implies that the EL measure is valid for C 2 solutions FE 1231.66 640000 0
only. The following example demonstrates these phenom- LE (C 1 ) 1067.33 1600000 1600000
ena. Consider the data set: LE (C 2 ) 58.70 3840000 0
n
X
200 200 = a x
(6 k ∆ k + 2bk ? 2bk+1 )2 (11)
k=0
0 g 0 g
800 g 800 g
The energy measure given in Eq. (11) can be minimized
subject to monotonicity constraints by using quadratic pro-
600 600 gramming:
n?
X2
a x b ? 2bk+1)2
400 400
(6 k ∆ k + 2 k
g g g g
MINIMIZE (12)
200 200 k=0
subject to:
0 g 0 g
5
shows the cubic spline elastica (CSE) obtained by minimiz-
ing Eq. (6). Table 2 summarizes the energy measures for ?
n 2
Fig. 6. Note that although the CSE is a C 2 monotone curve,
f "(x?k ) ? f "(x+k ) + K
X
the LE and SDDE curves could not yield that solution since
ED =
k=1
its (k , k ) set exists in the area lying outside the polygon n?2
and inside M . It is evident that the SDDE curve and its
X
= 6ak ∆xk + 2bk ? 2bk+1 + K (13)
energy measures are much closer to those of CSE than LE. k=0
800 800
The energy measure given in Eq. (13) can be minimized
g g subject to monotonicity constraints by using linear program-
600 600
ming:
?2
g g
400 400
n
X
6ak ∆xk + 2bk ? 2bk+1 + K
g g g g
MINIMIZE (14)
k=0
200 200
0 g 0 g
subject to:
3.
g g
400
g
400
g
The above constraints denote interpolation, first derivative
g g g g
6 RESULTS
Figure 6. (a) FE; (b) SDDE (c) C 1 LE (d) CSE.
In this section, we compare the results of the different
techniques described in this paper. The six methods com-
Method E EL ED pared are: CSE, FE, Fritsch & Butland (FB), LE, SDDE,
FE 855.84 343408.02 0 and MDE. We used the optimization toolbox of Matlab 5.2
SDDE 845.22 1601043.30 0.70 to solve the linear and quadratic programming problems
LE (C 1 ) 8.28 392688.93 666782.99 above. Note that Matlab indicates when no feasible solution
CSE 27.15 1504779.88 0 exists. We will demonstrate the techniques on the following
data set:
The quadratic programming formulation given above is Figures 7 to 10 depict the curves produced by the CSE,
not necessarily guaranteed to converge to the true (optimal) FE, SDDE, and FB methods, respectively. Each curve is
solution. As a result, we simplify the discontinuity en- presented in two coordinate systems: (x; f (x)) and (; ).
ergy measure ED to be linear with the cubic coefficients The purpose of this representation is to highlight the mono-
so that a linear programming procedure can be applied. tone characteristics of the curves. The spline figures con-
The simplification is done by adding an unknown constant tain vertical lines ended with circles to represent the second
K to each second derivative difference, such that the term derivative difference at the knots, where the difference is
f "(x?k ) ? f "(x+k ) + K is positive. The positivity of each measured by Dk = (f "(xk ?) ? f "(xk +))2 Note that ED is
term is obtained by adding it as an optimization constraint defined as the sum of all the Dk ’s. The scale for the second
where K is one of the optimization unknowns. derivative differences is normalized to fit the curve scale,
6
αk
4
αk 25 f.. g
... g
.. f..
4 20 .. ... 3
f.. g
25 f.. .. g ..
g .. ... .. ..
g
15 .. .. .. g ..
.. .. . g
f.. ..
20 g.
g
3 .. .. .. .. .. 2
g .. .. .. .. ..
g
g 10 .. f.. .. .. .. .. g g
15 g .. ... g. .. .. .. g
g
g
g
.. .. g
... .. .. .. g g g
2 5 .. g..
.. .. .. .. 1
.. .. .. .. .. ..
10 g
.. .. .. .. .. ..
f.. g
g g.
. .. f.. .. .. f . f.. .. .. gg
0 g g
5 g
g
1 0 g βk
gg
g
g g g
0 5 10 0 1 2 3 4
g g
0 g f f f f f f f f f f (a) (b)
0 βk
0 5 10 0 1 2 3 4
(a) (b) Figure 10. Fritsch-Butland (FB): (a) interpolat-
ing spline; (b) f; g points
Figure 7. Cubic spline elastica (CSE): (a) in-
terpolating spline; (b) f; g points
15 g
g
on the smoothness of the curve. In particular, the resulting
g
g
2 g
curve exhibits more tension and is biased towards linear
interpolation where (; ) = (1; 1). It is also salient that the
10 g
g
5 1
g
gg
g
g
second derivative discontinuities are prominent at the spline
g
g g
0 g f f f f f f f f f f
0 g βk joints. Table 3 summarizes these results. Note that the linear
0 5 10 0 1 2 3 4
(a) (b)
4
25 g
Table 3. Energy measures.
g g
20 g
3
g
g
15
g
g and quadratic programming procedures require specifying
g g
2
10 g
g an initial starting point for the minimization search. The
g
g
1
curves illustrated in the examples are obtained by setting
5 g
g
g
g
g g
the initial starting point to zero. As specified in previous
g g
0 f f f f f f f f f f
g
0 βk sections, it may happen that the solutions obtained with
0 5 10 0 1 2 3 4 quadratic programming do not reflect the optimal solution
(a) (b)
since it may get stuck in a local minima.
Figure 9. Second derivative discontinuity en-
ergy (SDDE): (a) interpolating spline; (b) 7 DISCUSSION
f; g points
In this section, we review several key points about mono-
tonic cubic spline interpolation.
7
1. By examining the physical definition of the strain en- They minimized the second derivative discontinuity and pro-
ergy, it is implicit that energy measures Eq. (6) and vided visually pleasing results.
Eq. (7) are applicable for C 2 curves only. This means
that the energy measures are only meaningful when References
comparing C 2 monotone splines. For instance, we can-
not use such energy measures to compare C 0 curves, [1] P. Costantini. An algorithm for computing shape-preserving
such as those produced by linear interpolation. It is ap- cubic spline interpolation to data. Calcolo., 21:295–305,
parent that such curves produce low values for E and 1984.
EL, although they are not smooth at the spline joints. [2] P. Costantini. On monotone and convex spline interpolation.
That is, they satisfy f 00 (x) = 0 nearly everywhere. Math. Comp., 46:203–214, 1986.
[3] P. Costantini. Co-monotone interpolating splines of arbitrary
Only at the spline joints is this condition possibly vio-
lated. Therefore, C 2 energy measures E and EL are not
degree: A local approach. SIAM J. Sci. Stat. Comp, 8:1026–
1034, 1987.
appropriate objective functions for monotone splines, [4] P. Costantini. An algorithm for computing shape-preserving
since the monotonicity constraint may sometimes force interpolating splines of arbitrary degree. J. Comp. Appl.
the spline to be C 1 continuous. Math, 22:89–136, 1988.
[5] C. de Boor. A Practical Guide to Splines. Springer-Verlag,
2. The assumption used to define EL is correct for a subset New York, 1978.
of C 2 curves that comply with the condition f 0 (x)2 [6] R. Delbourgo and J. Gregory. Shape preserving piecewise
1. This condition is often violated in practice. This rational interpolation. SIAM J. Sci. and Stat. Comp., 6:967–
makes the use of linearized energy EL meaningless as 976, 1985.
an objective function for optimization-based methods. [7] F. Fritsch and R. Carlson. Monotone piecewise cubic in-
terpolation. SIAM J. Numerical Analysis, 17(2):238–246,
For instance, in comparing the FE and the SDDE curves
in Fig. 6, higher E for the free-end (FE) curve does not
1980.
[8] F. N. Fritsch and J. Butland. A method for constructing local
translate to higher EL (see Table 2). monotone piecewise cubic interpolants. SIAM J. Sci. Stst.
3. The Fritsch-Butland algorithm clamps the and val-
Comput., 5(2), 1984.
[9] J. Gregory and R. Delbourgo. Piecewise rational quadratic
ues to the [0; 3] range, thereby utilizing only 67.9% interpolation to monotonic data. IMA J. Numerical Analysis,
of monotone region M . This has a tendency of bi- 2:123–130, 1982.
asing the solution away from smoother alternatives. [10] M. M. Malcolm. On the computation of nonlinear spline
The optimization-based solutions presented in this pa- functions. SIAM J. Numerical Analysis, 14(2):254–282,
per more fully utilize region M , yielding the smoother 1977.
[11] D. McAllister, E. Passow, and J. Roulier. Algorithms for
SDDE and MDE curves shown in the figures above.
computing shape preserving splines interpolations to data.
4. The global algorithm used to minimize the second Math. Comp., 31:717–725, 1977.
derivative discontinuity produces monotone C 2 solu-
[12] G. M. Nielson. Some piecewise polynomial alternatives to
splines under tension. In R. Barnhill and R. Riesenfeld,
tions, if they exist. This lies in contrast to the local editors, Computer Aided Geometric Design, pages 209–235.
Fritsch-Butland algorithm that produces C 1 solutions. Academic Press, New York, 1974.
[13] S. Pruess. Properties of splines in tension. J. of Approxima-
8 SUMMARY tion Theory, 17:86–96, 1976.
[14] S. Pruess. Alternatives to the exponential spline in tension.
Math. Comp., 33:1273–1281, 1979.
The goal of this work has been to determine the smoothest [15] S. Pruess. Shape preserving c2 cubic spline interpolation.
possible curve that passes through its control points while IMA J. Numerical Analysis, 13:493–507, 1993.
simultaneously satisfying the montonicity constraint. Vari- [16] D. Rogers and J. A. Adams. Mathematical Elements for
ous energy measures were considered for the optimization Computer Graphics. McGraw-Hill, New York, 1990.
[17] L. L. Schumaker. On shape oreserving quadratic spline in-
objective functions. We showed how to apply quadratic pro-
terpolation. SIAM J. Numerical Analysis, 20:854–864, 1983.
gramming to minimize the objective functions used in this [18] D. Schweikert. An interpolation curve using splines in ten-
paper. Modifications were introduced to simplify the prob- sion. J. Math and Phys., 45:312–317, 1966.
lem and facilitate the use of linear programming. We found [19] L. Shampine, J. R.C. Allen, and S. Pruess. Fundamentals
that optimization-based methods yielded superior results to of Numerical Computing. John Wiley and Sons, New York,
the popular Fritsch-Butland algorithm [8]. We showed that 1997.
the traditional linearized energy measure EL is based on [20] H. Späth. Exponential spline interpolation. Computing,
4:225–233, 1969.
invalid assumptions and is of limited value in determining
C 1 monotonic solutions. We suggested that the SDDE and
[21] G. Wolberg. Digital Image Warping. IEEE Computer Society
Press, Los Alamitos, CA, 1990.
MDE energy measures be used as optimization objectives.