Giter VIP home page Giter VIP logo

fastblur's Introduction

fastblur

Fast (linear time) implementation of the Gaussian Blur algorithm in Rust. Original taken from http://blog.ivank.net/fastest-gaussian-blur.html

Usage

The image is assumed to be an RGB image with three channels. This should change in the future, so you can blur as many channels as you want. Still WIP.

#[dependencies]
fastblur = { git = "https://github.com/fschutt/fastblur" }
use fastblur::gaussian_blur;

// data is a Vec<[u8;3]> - 3 items for R, G and B.
// This format will probably change.
gaussian_blur(&mut data, width, height, 10.0);

NOTE: This is not "the fastest" Gaussian blur. It currently takes 8ms - but it is independent of the blur size. A regular Gaussian blur depends on the size of the blur. At a 3px blur, the example from the imageproc library needs 4ms. At a 10px blur, it already needs 28ms. And so on. This library always needs 8ms, no matter of the size of the blur.

fastblur's People

Contributors

fschutt avatar shnatsel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastblur's Issues

Use iterators instead of indexing

It should be possible to make the code faster by using iterators instead of indexing, which lets the compiler eliminate bounds checks on every lookup. Using iterators also makes the code more readable.

I have WIP conversion of the horizontal pass to iterators that works and doesn't exhibit any artifacts, but has a higher effective blur radius. It can be found here: https://github.com/Shnatsel/fastblur/tree/iterators
I probably will not have the time to complete it, but somebody familiar with the algorithm should be able to fix the blur radius fairly easily.

Crash on blur_radius greater than image size

Lines such as

for j in 0..blur_radius {
assume that the blur radius is smaller than image size.

Specifically, the pixels that require blur to reach beyond the left edge are processed first, with the assumption that they will never need pixels from beyond the right edge in the same operation. So even if it's made to not crash it would produce incorrect results.

Blur order

Currently, we blur horizontally first, but it produces strange artifacts:

e-feGaussianBlur-001

(left - hor -> ver, right - ver -> hor)

Maybe we should blur vertically first?

create_box_gauss() allocates needlessly

create_box_gauss() currently returns a Vec<i32> with length specified by the input parameter n. Vectors are always allocated on the heap, which is costly. Even the tiny vectors of 3 elements add 3% to the total runtime, or 6% in asymmetric case that calculates the box twice.

Sadly const generics are not yet implemented in rustc so we cannot abstract it over the length of a slice, but we can work around this e.g. by returning an iterator.

In place

An in-place version would be nice.

Small typo in create_box_gauss in blur.rs?

This probably has very little effect on the output, but I noticed that the + 1.0 was after the sqrt, whereas the blog post has it inside the sqrt

Original:
let w_ideal = (12.0 * sigma * sigma / n_float).sqrt() + 1.0;

Suggested:
let w_ideal = (12.0 * sigma * sigma / n_float + 1.0).sqrt();

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.