Lanczos interpolation

eujin·2025년 12월 1일

Data Processing

목록 보기
1/3
post-thumbnail

1. Lanczos interpolation

이미지 또는 신호를 resampling 할 때 사용하는 보간 알고리즘

2. 원리 및 공식

sinc 함수를 짧은 길이의 window로 자른 필터 사용

L(x)={sinc(x)sinc ⁣(xa),x<a,0,otherwise.L(x)= \begin{cases} \mathrm{sinc}(x)\,\mathrm{sinc}\!\left(\frac{x}{a}\right), & |x|<a,\\ 0, & \text{otherwise}. \end{cases}
  • sinc(x) = sin(πx) / (πx)
  • a = Lanczos window size
  • Pillow Lanczos = a=3
  • OpenCV Lanczos4 = a=4

윈도우 크기만큼의 주변 픽셀을 참고해서 resampling 함

3. 코드

mnist (28*28)mnist(16*16) 으로의 변환이 필요했어서 예제는 16*16 resize 로 써둠
PIL, torch, cv 에서 사용할 수 있는 3가지 예제 코드임

from PIL import Image

img = Image.open("image.png")
img16 = img.resize((16, 16), resample=Image.LANCZOS)
from torchvision.transforms import Resize, InterpolationMode

resize_16 = Resize((16, 16), interpolation=InterpolationMode.LANCZOS)
import cv2

img = cv2.imread("image.png")
img16 = cv2.resize(img, (16,16), interpolation=cv2.INTER_LANCZOS4)

4. 유의점

sinc 기반이라 ringing 발생가능성이 있음
이미지 작을수록 심함
타 interpolation 보다 계산량 많음

0개의 댓글