owned this note
owned this note
Published
Linked with GitHub
---
title: torch.nn.functional.interpolate
---
## Task: smoothing
```python=
def smoothen_pillow(i: Image, f: int = 4):
w, h = i.width, i.height
assert w % f == 0
assert h % f == 0
i = i.resize((w // f, h // f), resample=BILINEAR)
i = i.resize((w, h), resample=BILINEAR)
return i
```
---
`PIL.Image.Image.resize(..., method=BILINEAR)`
<img src="https://i.imgur.com/VTD8lea.gif" style="width: 50%;" />
---
`F.interpolate(..., align_corners=False, antialias=True)`
<img src="https://i.imgur.com/vte93hr.gif" style="width: 50%;" />
---
`F.interpolate(..., align_corners=False, antialias=True)`
<table><tr>
<td style="width: 25%;">
<img src="https://i.imgur.com/vte93hr.gif" style="width: 100%;" />
</td>
<td>
<ul>
<li>No shifts</li>
<li>Surprisingly close to PIL</li>
</ul>
</td>
</tr></table>
---
PIL vs interpolate(no align, AA)
<img src="https://i.imgur.com/fnDLPr6.gif" style="width: 50%;" />
---
`F.interpolate(..., align_corners=True, antialias=True)`
<img src="https://i.imgur.com/R2IbBVE.gif" style="width: 50%;" />
---
`F.interpolate(..., align_corners=True, antialias=True)`
<table><tr>
<td style="width: 25%;">
<img src="https://i.imgur.com/R2IbBVE.gif" style="width: 100%;" />
</td>
<td>
<ul>
<li>Still no shifts</li>
<li>A "cross" (image of the filter?)</li>
</ul>
</td>
</tr></table>
---
`F.interpolate(..., align_corners=True, antialias=False)`
<img src="https://i.imgur.com/aan2dV8.gif" style="width: 50%;" />
---
`F.interpolate(..., align_corners=True, antialias=False)`
<table><tr>
<td style="width: 25%;">
<img src="https://i.imgur.com/aan2dV8.gif" style="width: 50%;" />
</td>
<td>
<ul>
<li>Still no shifts</li>
<li>Two darkened strips plus darkened blocks</li>
</ul>
</td>
</tr></table>
---
`resize_right.resize`
<img src="https://i.imgur.com/3EE4GW2.gif" style="width: 50%;" />
---
`resize_right.resize`
<table><tr>
<td style="width: 25%;">
<img src="https://i.imgur.com/3EE4GW2.gif" style="width: 50%;" />
</td>
<td>
<ul>
<li>Darkening along the borders</li>
</ul>
</td>
</tr></table>
---
`F.interpolate(..., align_corners=False, antialias=True)`
<img src="https://i.imgur.com/4ppyVTO.gif" style="width: 50%;" />
---
`PIL.Image.Image.resize(..., method=BILINEAR)`
<img src="https://i.imgur.com/hz5DBOw.gif" style="width: 50%;" />
---
interpolate vs PIL
<img src="https://i.imgur.com/bmAC59e.gif" style="width: 50%;" />
---
What does `torch` actually use?
---

---
`HelperInterpLinear::aa_filter`

---

---
...