stackblur

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 2 Imported by: 0

README

stackblur-go

GoDoc Build Status

This is a Go port of Stackblur algorithm created by Mario Klingemann.

Stackblur is a compromise between Gaussian blur and Box blur, but it creates much better looking blurs than Box blur and it is ~7x faster than Gaussian blur.

Comparing to the Javascript implementation the Go version is at least 50% faster (depending on the image size and blur radius), running the same image with the same bluring radius.

Benchmark
Radius Javascript Go
20 ~15ms ~7.4ms

Installation

First, install Go, set your GOPATH, and make sure $GOPATH/bin is on your PATH.

$ export GOPATH="$HOME/go"
$ export PATH="$PATH:$GOPATH/bin"

Next build the binary file.

$ go get -u github.com/esimov/stackblur-go/cmd
CLI example

The provided CLI example supports the following flags:

$ stackblur --help

Usage of stackblur:
  -gif
    	Output Gif
  -in string
    	Source
  -out string
    	Destination
  -radius int
    	Radius (default 20)

The command below will generate the blurred version of the source image.

$ stackblur -in image/sample.png -out image/output.png -radius 10

The cli command supports a -gif flag, which if set as true it visualize the bluring process by outputting the result into a gif file.

API call

The API is very simple: you have to expose an image file and a blur radius to the Process function.

stackblur.Process(src, blurRadius)

Results

Original image Blured image

License

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Overview

stackblur-go is a Go port of the Stackblur algorithm.

Stackblur is a compromise between Gaussian blur and Box blur, but it creates much better looking blurs than Box blur and it is ~7x faster than Gaussian blur.

The API is very simple and easy to integrate into the project. There is a single publicly exposed `Process` functions which receive an image and a radius as parameters and returns the blurred version of the provided image.

func Process(src image.Image, radius uint32) image.Image

Below is a very simple example of how you can use this package.

package main

import (
	"image"
	"image/jpeg"
	"log"
	"os"

	"github.com/esimov/stackblur-go"
)

func main() {
	img, err := os.Open("sample.jpg")
	defer img.Close()

	src, _, err := image.Decode(img)
	if err != nil {
		log.Fatal(err)
	}

	res := stackblur.Process(src, uint32(5))

	output, err := os.OpenFile("output.jpg", os.O_CREATE|os.O_RDWR, 0755)
	defer output.Close()
	if err != nil {
		log.Fatal(err)
	}

	if err = jpeg.Encode(output, res, &jpeg.Options{Quality: 100}); err != nil {
		log.Fatal(err)
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(src image.Image, radius uint32) image.Image

Process takes an image as input and returns it's blurred version by applying the blur radius defined as parameter.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL