https://github.com/vaisest/bicubic-intepolation-py
Bicubic convolution interpolation implementation in Python and Rust from Keys, 1981
https://github.com/vaisest/bicubic-intepolation-py
bicubic-interpolation bicubic-kernels image-processing image-scaling
Last synced: 5 months ago
JSON representation
Bicubic convolution interpolation implementation in Python and Rust from Keys, 1981
- Host: GitHub
- URL: https://github.com/vaisest/bicubic-intepolation-py
- Owner: vaisest
- License: gpl-2.0
- Created: 2023-10-27T07:16:54.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T19:08:40.000Z (about 2 years ago)
- Last Synced: 2024-03-26T20:27:39.594Z (about 2 years ago)
- Topics: bicubic-interpolation, bicubic-kernels, image-processing, image-scaling
- Language: Rust
- Homepage:
- Size: 63.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://ieeexplore.ieee.org/document/1163711) 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
```math
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](https://imagemagick.org/Usage/filter/).