Git Product home page Git Product logo

libblur's Introduction

Fast blur algorithms library for Rust

There are some very good and blazing fast algorithms that do blurring images. Best optimized for NEON and SSE.

You may receive gaussian blur in 100 FPS for 4K photo.

Much faster than image default blur.

When 4-channels mode is in use that always considered that alpha channel is the last.

Also there are some available options to perform blurring in linear colorspace, or if methods do not fit you f32 options also available

Performance

Most blur algorithms done very good and works at excellent speed. Where appropriate comparison with OpenCV is available. For measurement was used M3 Pro with NEON feature. On x86_84 OpenCV might be better sometimes since AVX-2 is not fully supported in library

Usage

cargo add libblur

Stack blur

The fastest with acceptable results. Result are quite close to gaussian and look good. Sometimes noticeable changes may be observed. However, if you'll use advanced analysis algorithms non gaussian methods will be detected. Not suitable for antialias. Results just a little worse than in 'fast gaussian', however it's faster.

O(1) complexity.

libblur::stack_blur( & mut bytes, stride, width0, height, radius, FastBlurChannels::Channels3);

Example comparison time for blurring image 3000x4000 RGB 8-bit in single-threaded mode with 77 radius.

Time
libblur 43.58ms
OpenCV 89.64ms

Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded mode with 77 radius.

Time
libblur 8.68ms
OpenCV 87.99ms

Example comparison time for blurring image 2828x4242 RGBA 8-bit in multithreaded mode with 77 radius.

Time
libblur 6.73ms
OpenCV 93.26ms

Example comparison time for blurring image 2828x4242 RGBA 8-bit in single-threaded mode with 77 radius.

Time
libblur 31.18ms
OpenCV 90.82ms

Fast gaussian

Very fast. Result are quite close to gaussian and look good. Sometimes noticeable changes may be observed. However, if you'll use advanced analysis algorithms non gaussian methods will be detected. Not suitable for antialias. Do not use when you need gaussian. Based on binomial filter, generally speed close, might be a little faster than stack blur ( except NEON or except non multithreaded stack blur, on NEON much faster or overcome non multithreaded stackblur ), however results better as I see. Max radius ~320 for u8, for u16 will be less.

O(log R) complexity.

libblur::fast_gaussian( & mut bytes, stride, width0, height, radius, FastBlurChannels::Channels3);

Example comparison time for blurring image 3000x4000 RGB 8-bit in single-threaded mode with 77 radius.

Time
libblur 47.40ms
OpenCV -

Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded mode with 77 radius.

Time
libblur 9.95ms
OpenCV -

Example comparison time for blurring image 2828x4242 RGBA 8-bit in multithreaded mode with 77 radius.

Time
libblur 9.74ms
OpenCV --

Example comparison time for blurring image 2828x4242 RGBA 8-bit in single-threaded mode with 77 radius.

Time
libblur 43.60ms
OpenCV --

Fast gaussian next

Very fast. Produces very pleasant results close to gaussian. If 4K photo blurred in 10 ms this method will be done in 15 ms. Max radius ~150-180 for u8, for u16 will be less.

O(log R) complexity.

libblur::fast_gaussian_next( & mut bytes, stride, width, height, radius, FastBlurChannels::Channels3);

Example comparison time for blurring image 3000x4000 RGB 8-bit in single-threaded mode with 77 radius.

Time
libblur 53.99ms
OpenCV -

Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded mode with 77 radius.

Time
libblur 10.26ms
OpenCV -

Tent blur

2 sequential box blur ( theory ) that produces a tent filter. Medium speed, good-looking results with large radius tents becoming more noticeable

O(1) complexity.

libblur::tent_blur(bytes, stride, & mut dst_bytes, stride, width, height, radius, FastBlurChannels::Channels3);

Median blur

Median blur ( median filter ). Implementation is fast enough.

O(log R) complexity.

libblur::median_blur(bytes, stride, & mut dst_bytes, stride, width, height, radius, FastBlurChannels::Channels3);

Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded mode with 35 radius.

Time
libblur 468.47ms
OpenCV 725.89ms

Example comparison time for blurring image 2828x4242 RGBA 8-bit in multithreaded mode with 35 radius.

Time
libblur 643.22ms
OpenCV 788.93ms

Gaussian blur

Excellent results. Have improvements, however, much slower than any approximations slow. Use when use need gaussian methods - smoothing, anti-alias, FFT, advanced analysis etc.

Kernel size must be odd. Will panic if kernel size is not odd.

O(R) complexity.

libblur::gaussian_blur( & bytes, src_stride, & mut dst_bytes, dst_stride, width, height, kernel_size, sigma, FastBlurChannels::Channels3);

Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded mode with 151 kernel size.

Time
libblur 122.02ms
OpenCV 251.10ms

Example comparison time for blurring image 2828x4242 RGBA 8-bit in multithreaded mode with 151 kernel size.

Time
libblur 131.21ms
OpenCV 193.67ms

Example comparison time for blurring image 3000x4000 single plane 8-bit in multithreaded mode with 151 kernel size.

Time
libblur 41.65ms
OpenCV 75.94ms

Gaussian box blur

Generally 3 sequential box blurs it is almost gaussian blur ( theory ), slow, really pleasant results. Medium speed.

O(1) complexity.

libblur::gaussian_box_blur(bytes, stride, & mut dst_bytes, stride, width, height, radius, FastBlurChannels::Channels3);

Box blur

Box blur. Compromise speed with bad looking results. Medium speed.

O(1) complexity.

libblur::box_blur(bytes, stride, & mut dst_bytes, stride, width, height, radius, FastBlurChannels::Channels3);

Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded mode with 77 radius.

Time
libblur 14.08ms
OpenCV 96.41ms

Example comparison time for blurring image 3000x4000 RGB 8-bit in single-threaded mode with 77 radius.

Time
libblur 57.47ms
OpenCV 92.66ms

Example comparison time for blurring image 2828x4242 RGBA 8-bit in multithreaded mode with 77 radius.

Time
libblur 12.79ms
OpenCV 136.66ms

Example comparison time for blurring image 2828x4242 RGBA 8-bit in single-threaded mode with 77 radius.

Time
libblur 51.90ms
OpenCV 134.28ms

libblur's People

Contributors

awxkee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

akinsella

libblur's Issues

Request for Grayscale (Single Channel) Gaussian Blur Support

Hello,

First of all, thank you for providing such a useful library!

Currently, libblur supports Gaussian blur for images with 3 or 4 channels, as indicated by the FastBlurChannels enum:

#[repr(C)]
pub enum FastBlurChannels {
    Channels3 = 3,
    Channels4 = 4,
}

However, I often work with grayscale images which only have a single channel. It would be incredibly helpful if libblur could support Gaussian blur for single channel (grayscale) images as well.

Would it be possible to extend the FastBlurChannels enum and the underlying implementation to support single channel images?

Thank you for considering this feature request!

Usage with DynamicImage or ImageBuffer

I am using this to add blur to my image. I converted the Dynamic Image into bytes but didn't know how to calculate stride. Thus, either provide a guide to calculate the values or implement a function that automatically parse the values from the passed image.

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.