Graphics Reference
In-Depth Information
Listing 19.1: Evaluating the original signal by convolving source image
samples with sinc.
// Reconstruct a value for the signal
S
from 300 samples in the
// image called "source".
double
S(x, source) {
double
y = 0.0;
for
(
int
i = 0; i < 300; i++) {
y += source[i]
*
sinc(x - i);
1
2
3
4
5
6
7
8
9
}
return
y;
}
Notice that the sum is finite because we've assumed that
source[i]
is
0
except
for
i
=
0,
...
, 299. In general, the sum would have to be infinite, or, in practice, a
sum over a very wide interval.
Now that we've reconstructed the original band-limited function,
S
, we need
to scale it up to produce a new function
T
. If we think of each sample of
S
as
representing the value of
S
at the middle of a unit interval, then the 300 samples
we have for
S
, at locations 0,
...
, 299, represent
S
on the interval
[
−
0.5, 299.5
]
.
We want to stretch this interval to
[
−
0.5, 399.5
]
.
To do so, we write
T
(
x
)=
S
300
0.5
.
400
(
x
+
0.5
)
−
(19.5)
Once again, rather than building the signal
T
, we've merely provided a practical
way to evaluate it at any point where we need it.
Inline Exercise 19.1:
Verify that
T
(
−
0.5
)=
S
(
−
0.5
)
and
T
(
399.5
)=
S
(
299.5
)
.
We must now sample
T
at integer locations. Since
T
is band-limited, it must
be continuous, so sampling at
x
amounts to evaluation at
x
.
Clearly the numbers 300 and 400 can be generally replaced by numbers
N
and
K
where
K
N
, and every step of the process remains unchanged. The resultant
code is shown in Listing 19.2.
>
Listing 19.2: Scaling up a one-dimensional source image.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Scale the N-pixel source image up to a K-pixel target image.
void
scaleup(source, target, N, K)
{
assert(K >= N);
for
(j=0;j<K;j++) {
target[j] = S((N/K)
*
(j + 0.5) - 0.5 , source, N );
}
}
double
S(x, source, N) {
double
y = 0.0;
for
(
int
i = 0; i < N; i++) {
y += source[i]
*
sinc(x - i);
}
return
y;
}