Professional Documents
Culture Documents
1.4. Image Interpolation - IMPORTANTE
1.4. Image Interpolation - IMPORTANTE
1.4. Image Interpolation - IMPORTANTE
In most cases it is not realis c to ask for the value f (x, y): a unique value only exists in case
the sampling proces is without loss of informa on. For band-limited images indeed such a
unique interpolated func on exists, because ideal bandlimited images (func ons) can be
sampled without loss and thus can be reconstructed without error. [#fn_bandlimited]_
In these lecture notes we start from a rather pragma c point of view. We assume that the
digital images we start with are oversampled i.e. the samples are close enough to eachother
to faithfully represent the image f . Surely we have to take care not to undersample images in
our computa onal analysis without presmoothing as we would be computa onally
introducing aliasing then.
In this sec on we start with interpola on for 1D func ons, that is we start with interpola on
of sampled univariate func ons. We will discuss only a few techniques that are commonly
used. Then we show how to generalize these 1D interpola on methods to 2D (and nD if
needed).
Nearest neighbor interpola on is the simplest interpola on method. Given the samples F (k)
the value of the interpolated func on f^ at coordinate x is given as:
^ 1
f (x) = F (⌊x + ⌋)
2
i.e. we simply select the sample point that is nearest to x. Here ⌊x⌋ is the floor func on, i.e.
the largest integer values that is less then or equal to x.
This leads to a staircase type of interpolated func on. The func on f^ is indeed defined on
the en re real axis but it is neither con nuous (as it contains jumps) nor differen able. /
As an example we look at the func on f (x) = sin(x) and its nearest neighbor interpolated
version.
In [4]: f = np.sin(x); F = np.sin(xs); # the 'continuous' function and its sampled version
In green the con nuous func on f (note that we did sample this func on too… but we did so
with a very small sample width and thus for our eye the plot looks like a con nuous func on),
in red the sampled func on and in blue the interpolated func on.
Linear interpola on is the scien fic equivalent of what you have already learned in
kindergarten: connect the dots. Between to adjacent sample points k and k + 1 we assume
the func on is a linear func on and thus in this interval [k, k + 1] we have:
^
k ≤ x ≤ k + 1 : f (x) = (1 − (x − k))F (k) + (x − k)F (k + 1)
/
The linearly interpolated func on is con nuous but it is not everywhere differen able (in de
sample points it’s not differen able). Furthermore for the interpolated func on the second
and higher order deriva ves are equal zero (except for the sample points where these are not
defined).
Although a simple interpola on method, linear interpola on is very o en used in prac ce. It
is simple to implement and very fast.
In nearest neighbor interpola on only one sample is used (the nearest) to set the interpolated
value. In linear interpola on we look at the 2 closest sample points (one on the le and one
on the right). For cubic interpola on we look at two pixels on the le and two on the right.
^ 3 2
k ≤ x ≤ k + 1 : f (x) = ax + bx + cx + d
3 2
F (k − 1) = a(−1) + b(−1) + c(−1) + d
F (k) = d
3 2
F (k + 1) = a(1) + b(1) + c(1) + d
3 2
F (k + 2) = a(2) + b(2) + c(2) + d
/
1
a = (−F (k − 1) + 3F (k) − 3F (k + 1) + F (k + 2))
6
1
b = (F (k − 1) − 2F (k) + F (k + 1))
2
1
c = (−2F (k − 1) − 3F (k) + 6F (k + 1) − F (k + 2))
6
d = F (k)
In [11]: xs = np.arange(-7, 8)
In [17]: plt.show()
/
Another disadvantage of the interpola on schemes discussed so far is that the piecewise
interpolated func on f^ shows discon nui es at the sample point posi ons. This
disadvantage can be tackled with spline interpola on.
Assume that x = i + a and y = j + b (with a and b in the interval [0, 1]) then:
abF (i + 1, j + 1)
When generalizing cubic interpola on to two dimensions we need 16 samples in the image (a
4 × 4 subgrid).