-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanczos-interpolation.html
More file actions
377 lines (334 loc) · 12.2 KB
/
lanczos-interpolation.html
File metadata and controls
377 lines (334 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="msapplication-TileColor" content="#603cba">
<meta name="theme-color" content="#ffffff">
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
<link rel="manifest" href="/favicon/site.webmanifest">
<link rel="mask-icon" href="/favicon/safari-pinned-tab.svg" color="#5bbad5">
<link rel="stylesheet" href="/assets/css/reveal.css">
<link rel="stylesheet" href="/assets/css/theme/custom.css">
<link rel="stylesheet" href="/assets/icons/style.css">
<link rel="stylesheet" href="/assets/js/reveal-plugins/highlight/night-owl.min.css">
<link rel="stylesheet" href="/assets/css/common.css">
<link rel="stylesheet" href="/assets/css/page.css">
<script src="/assets/js/reveal-plugins/highlight/highlight.min.js"></script>
<script src="/assets/js/reveal-plugins/highlight/highlightjs-line-numbers.min.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("End", function () {
setTimeout(function(){
screenh = window.innerHeight;
headerh = document.getElementById('header-nav').offsetHeight;
document.querySelector('.reveal').style.height = (screenh - headerh) + 'px';
update_height(screenh, headerh);
handleMathOverflow();
handleSvgSize(screenh, headerh);
handleCode(screenh, headerh);
}, 500)
});
</script>
<!-- Begin Jekyll SEO tag v2.7.1 -->
<title>Lanczos Interpolation | SlideMe</title>
<meta name="generator" content="Jekyll v4.2.1" />
<meta property="og:title" content="Lanczos Interpolation" />
<meta name="author" content="Edgardo Estanga" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="To interpolate a value with Lanczos interpolation, we do a weighted sum of the surrounding values, using the Lanczos kernel as the weight function." />
<meta property="og:description" content="To interpolate a value with Lanczos interpolation, we do a weighted sum of the surrounding values, using the Lanczos kernel as the weight function." />
<link rel="canonical" href="https://isedgar.github.io/lanczos-interpolation.html" />
<meta property="og:url" content="https://isedgar.github.io/lanczos-interpolation.html" />
<meta property="og:site_name" content="SlideMe" />
<meta property="og:image" content="https://isedgar.github.io/assets/images/lanczos-interpolation.jpg" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2021-11-10T00:00:00-04:00" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:image" content="https://isedgar.github.io/assets/images/lanczos-interpolation.jpg" />
<meta property="twitter:title" content="Lanczos Interpolation" />
<script type="application/ld+json">
{"@type":"BlogPosting","url":"https://isedgar.github.io/lanczos-interpolation.html","image":"https://isedgar.github.io/assets/images/lanczos-interpolation.jpg","headline":"Lanczos Interpolation","dateModified":"2021-11-10T00:00:00-04:00","datePublished":"2021-11-10T00:00:00-04:00","author":{"@type":"Person","name":"Edgardo Estanga"},"description":"To interpolate a value with Lanczos interpolation, we do a weighted sum of the surrounding values, using the Lanczos kernel as the weight function.","mainEntityOfPage":{"@type":"WebPage","@id":"https://isedgar.github.io/lanczos-interpolation.html"},"@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->
</head>
<body>
<header id="header-nav" class="page-flex flex-align-center">
<a href="/#/topics" id="go2topics"><i class="icon-back-s"></i></a>
<p class="p-font"> 2021-11-10</p>
</header>
<div class="reveal">
<div class="slides">
<section id="s0">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h1 class="h1-font">Lanczos Interpolation</h1>
<h3 class="h3-font txt-yellow">The Lanczos filter</h3>
</div>
</div>
</div>
</div>
</section>
<section id="s1">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">The <a href="https://www.oxfordlearnersdictionaries.com/us/" target="_blank">Oxford English Dictionary</a> defines interpolation as "the act of adding a value into a series by calculating it from surrounding known values".</h3>
</div>
</div>
</div>
</div>
</section>
<section id="s2">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">For example, we have a set of values:</h3>
<div class="h3-font math-overflow">
\[
\begin{align}
&S = (2, 0, 1.5, 1)\\\\
&s_0 = 2,\quad s_1 = 0,\quad s_2 = 1.5,\quad s_3 = 1
\end{align}
\]
</div>
</div>
</div>
</div>
</div>
</section>
<section id="s3">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<div class="svg"></div>
</div>
</div>
</div>
</div>
</section>
<section id="s4">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">and we add a value at \(x=1.4\), between \(s_1\) and \(s_2\):</h3>
<div class="h3-font math-overflow">
\[
\begin{align}
&S = (2, 0, ?, 1.5, 1)\\\\
&s_1 = 0,\quad s_{1.4} =\:?,\quad s_2 = 1.5
\end{align}
\]
</div>
</div>
</div>
</div>
</div>
</section>
<section id="s5">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<div class="svg"></div>
</div>
</div>
</div>
</div>
</section>
<section id="s6">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">The interpolation value depends on the interpolation method. For example, with <a href="/linear-interpolation.html" target="_blank">linear interpolation</a> the value is \(0.6\):</h3>
</div>
</div>
</div>
</div>
</section>
<section id="s7">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<div class="svg"></div>
</div>
</div>
</div>
</div>
</section>
<section id="s8">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">To interpolate a value with <a href="https://en.wikipedia.org/wiki/Lanczos_resampling" target="_blank">Lanczos interpolation</a>, we do a <a href="https://en.wikipedia.org/wiki/Weight_function" target="_blank">weighted sum</a> of the surrounding values:</h3>
<div class="h3-font math-overflow">
\[
S(x) = \displaystyle \sum_{i=\lfloor x \rfloor - a + 1}^{\lfloor x \rfloor + a} s_i L(x - i)
\]
</div>
</div>
</div>
</div>
</div>
</section>
<section id="s9">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">Where \(\lfloor x \rfloor\) is the <a href="https://en.wikipedia.org/wiki/Floor_and_ceiling_functions" target="_blank">floor function</a>; \(a\) is a possitive integer (2 throughout this example); \(L(x)\) is the weight function (the Lanczos filter):</h3>
</div>
</div>
</div>
</div>
</section>
<section id="s10">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<div class="h3-font math-overflow">
\[
L(x) =
\begin{cases}
1 & \quad \text{if } x = 0\\
\frac{a\:sin(\pi x) sin(\pi x / a)}{\pi^2 x^2} & \quad \text{if } -a \leq x < a\\
0 & \quad \text{otherwise.}
\end{cases}
\]
</div>
</div>
</div>
</div>
</div>
</section>
<section id="s11">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">This function in <a href="https://www.python.org/" target="_blank">Python</a> would be like:</h3>
<h3 class="h3-font">
<pre class="code">
<code class="language-python">from numpy import pi, sin
a = 2
def L(x):
if x == 0: return 1
elif -a <= x < a:
return a*sin(pi*x)*sin(pi*x/a) / (pi**2 * x**2)
else: return 0
</code>
</pre>
</h3>
</div>
</div>
</div>
</div>
</section>
<section id="s12">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">For example, the value at \(1.4\) gives us:</h3>
<div class="h3-font math-overflow">
\[
\begin{align}
&S(1.4) = \displaystyle \sum_{i=0}^{3} s_i L(1.4 - i)\\
&S(1.4) = s_0 L(1.4) + s_1 L(0.4) + s_2 L(-0.6) + s_3 L(-1.6)\\
&S(1.4) \approx 0.4463
\end{align}
\]
</div>
</div>
</div>
</div>
</div>
</section>
<section id="s13">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<div class="svg"></div>
</div>
</div>
</div>
</div>
</section>
<section id="s14">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<h3 class="h3-font">Python code:</h3>
</div>
</div>
</div>
</div>
</section>
<section id="s15">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<div class="h3-font">
<pre class="code"><code class="language-python">from numpy import pi, sin, floor
a = 2
def L(x):
if x == 0: return 1
elif -a <= x < a:
return a*sin(pi*x)*sin(pi*x/a) / (pi**2 * x**2)
else: return 0
# ys: y-coordinates
# x: any value between 0 and len(ys) - 1
def lanczos_query(ys, x):
n = ys.shape[0]
if x < 0 or x > n-1:
raise ValueError('value x must be between 0 and n-1')
y = 0.0
for i in range(int(floor(x)-a+1), int(floor(x)+a+1)):
j = i
if i < 0: j = 0
elif i > n-1: j = n-1
y += ys[j] * L(x - i)
return y
</code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="s16">
<div style="position: relative;">
<div class="div-outer">
<div class="div-middle">
<div class="div-inner">
<p class="p-font">Watch the video:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/ijmd6XyG2HA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<script src="/assets/js/reveal.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@latest/dist/svg.min.js"></script>
<script src="/assets/js/reveal-plugins/math/math.js"></script>
<script src="/assets/js/common.js"></script>
<script src="/assets/js/page.js"></script>
<script src="/assets/js/lanczos-interpolation.js"></script>
</body>
</html>