Skip to content

Bicubic convolution interpolation implementation in Python and Rust from Keys, 1981

License

Notifications You must be signed in to change notification settings

vaisest/Bicubic-intepolation-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bicubic interpolation in Python and Rust

This repository contains an image scaling implementation using the bicubic convolution interpolation algorithm written in Python for learning purposes. As the Python version is unusably slow, there is also a Rust implementation included that is quite fast and which might be useful for quickly scaling a large amount of images. Using RUSTFLAGS='-C target-cpu=native might be useful as there is no manual SIMD usage, but the Rust code works well with auto vectorization, resulting in doubled performance in my tests.

The method was originally introduced in Cubic convolution interpolation for digital image processing by R. Keys in 1981. The method works using the function $$g(x, y) = \sum_{l=-1}^2 \sum_{m=-1}^2 c_{i + l,j + m} u(dx + l) u(dy + m),$$ which produces a new value for a position $(x, y)$ in the new image by scaling these coordinates back to the dimensions of the source image as $(i, j)$, and then by summing the nearest 16 pixels. The weights are calculated using each pixel's distance using the function $u$ which is known as the interpolation kernel. There are multiple kernels available, but for example the one used in Keys' research was

$$u(s) = \begin{cases} \frac{3}{2} \left| s \right|^3 - \frac{5}{2} \left| s \right|^2 + 1 & 0 \leq \left| s \right| < 1 \\\ -\frac{1}{2} \left| s \right|^3 + \frac{5}{2} \left| s \right|^2 - 4 \left| s \right| + 2 & 1 \leq \left| s \right| < 2 \\\ 0 & \text{else}. \end{cases}$$

Some other kernels like the Mitchell-Netravali filter are also implemented. Generally different kernels affect the sharpness of the produced image. For more information on reconstruction filters / kernels see ImageMagick's documentation.

About

Bicubic convolution interpolation implementation in Python and Rust from Keys, 1981

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published