Giter Site home page Giter Site logo

vaisest / bicubic-intepolation-py Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 65 KB

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

License: GNU General Public License v2.0

Python 45.98% Rust 54.02%
bicubic-interpolation bicubic-kernels image-processing image-scaling

bicubic-intepolation-py's Introduction

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.

bicubic-intepolation-py's People

Contributors

vaisest avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.