Fast (linear time) implementation of the Gaussian Blur algorithm in Go.

Overview

Song2

Fast (linear time) implementation of the Gaussian Blur algorithm in Go.

Original algorithm taken from http://blog.ivank.net/fastest-gaussian-blur.html, and use goroutine.

Install & Usage

Package

Download and compile from this repository.

go get -u github.com/matsuyoshi30/song2

And import as a package, call the API song2.GaussianBlur(src, blurRadius).

package main

import (
    "fmt"
    "image"
    "image/png"
    "os"

    "github.com/matsuyoshi30/song2"
)

func main() {
    img, err := os.Open("./input.png")
    if err != nil {
        fmt.Println(err)
        return
    }

    img, _, err := image.Decode(file)
    if err != nil {
        fmt.Println(err)
        return
    }

    blured := song2.GaussianBlur(img, 3.0)

    out, err := os.Create("./output.png")
    if err != nil {
        fmt.Println(err)
        return
	}

    if err := png.Encode(out, blured); err != nil {
        fmt.Println(err)
        return
    }
}

CLI tool

Clone this repository, and go install.

git clone https://github.com/matsuyoshi30/song2
cd song2/cmd/song2 && go install

You can use song2 as a cli tool.

Usage:
  song2 [FLAGS] [FILE]

FLAGS:
  -o  Write output image to specifig filepath [default: blured.png]
  -r  Radius [default: 3.0]

Author:
  matsuyoshi30 <[email protected]>

Example

song2 -o assets/blured.png assets/sample.png

Original Blured
original blured

This image is from http://sipi.usc.edu/database/database.php?volume=misc&image=10#top

Benchmark

I also implemented another algorithms of this post in test package (AnotherAlgorithm1-3).

% go test -bench . -benchmem
goos: darwin
goarch: amd64
pkg: github.com/matsuyoshi30/song2
cpu: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
BenchmarkGaussianBlurAnotherAlgorithm1-4   	       1	10073325776 ns/op	 3145888 B/op	  262148 allocs/op
BenchmarkGaussianBlurAnotherAlgorithm2-4   	       1	1365498035 ns/op	 5243088 B/op	  786440 allocs/op
BenchmarkGaussianBlurAnotherAlgorithm3-4   	       4	 318496693 ns/op	11534604 B/op	 2359301 allocs/op
BenchmarkGaussianBlur-4                    	      51	  24086941 ns/op	 2097965 B/op	      12 allocs/op
BenchmarkStackblur-4                       	      48	  24818379 ns/op	 3146072 B/op	  524301 allocs/op
BenchmarkBildBlur-4                        	      30	  37115297 ns/op	 4244496 B/op	      21 allocs/op

reference stackblur-go and bild.

LICENSE

MIT

Author

matsuyoshi30

You might also like...
Another AOC repo (this time in golang!)

advent-of-code Now with 100% more golang! (It's going to be a long advent of code...) To run: Get your data for a given year/day and copy paste it to

Fast, simple sklearn-like feature processing for Go
Fast, simple sklearn-like feature processing for Go

go-featureprocessing Fast, simple sklearn-like feature processing for Go Does not cross cgo boundary No memory allocation No reflection Convenient ser

A fast userspace CSPRNG

frand go get lukechampine.com/frand frand is a fast-key-erasure CSPRNG in userspace. Its output is sourced from the keystream of a ChaCha cipher, muc

fast integer log base 10

Package log10 calculates log base 10 of an integer, fast. It is inspired by Daniel Lemire's blog post on this topic. TODO: Add implementations for oth

How fast could I write tic tac toe in Go, while not knowing Go, but with the aid of GitHub Copilot?

tictactoe-go-with-copilot How fast could I write tic tac toe in Go, while not knowing Go, but with the aid of GitHub Copilot? This took me about 30 mi

k-modes and k-prototypes clustering algorithms implementation in Go

go-cluster GO implementation of clustering algorithms: k-modes and k-prototypes. K-modes algorithm is very similar to well-known clustering algorithm

An implementation of Neural Turing Machines
An implementation of Neural Turing Machines

Neural Turing Machines Package ntm implements the Neural Turing Machine architecture as described in A.Graves, G. Wayne, and I. Danihelka. arXiv prepr

Implementation of E(n)-Equivariant Graph Neural Networks, in Pytorch
Implementation of E(n)-Equivariant Graph Neural Networks, in Pytorch

EGNN - Pytorch Implementation of E(n)-Equivariant Graph Neural Networks, in Pytorch. May be eventually used for Alphafold2 replication.

A high performance go implementation of Wappalyzer Technology Detection Library

wappalyzergo A high performance port of the Wappalyzer Technology Detection Library to Go. Inspired by https://github.com/rverton/webanalyze. Features

Owner
Masaya Watanabe
Masaya Watanabe
A native Go clean room implementation of the Porter Stemming algorithm.

Go Porter Stemmer A native Go clean room implementation of the Porter Stemming Algorithm. This algorithm is of interest to people doing Machine Learni

Charles Iliya Krempeaux 183 Jan 3, 2023
Golang implementation of the Paice/Husk Stemming Algorithm

##Golang Implementation of the Paice/Husk stemming algorithm This project was created for the QUT course INB344. Details on the algorithm can be found

Aaron Groves 29 Sep 27, 2022
k-means clustering algorithm implementation written in Go

kmeans k-means clustering algorithm implementation written in Go What It Does k-means clustering partitions a multi-dimensional data set into k cluste

Christian Muehlhaeuser 414 Dec 6, 2022
Genetic Algorithm and Particle Swarm Optimization

evoli Genetic Algorithm and Particle Swarm Optimization written in Go Example Problem Given f(x,y) = cos(x^2 * y^2) * 1/(x^2 * y^2 + 1) Find (x,y) suc

Guillaume Simonneau 26 Dec 22, 2022
Golang Genetic Algorithm

goga Golang implementation of a genetic algorithm. See ./examples for info on how to use the library. Overview Goga is a genetic algorithm solution wr

null 177 Dec 19, 2022
An iterative algorithm to generate high-quality triangulated images.

An iterative algorithm to generate high quality triangulated images. Introduction Triangula uses a modified genetic algorithm to triangulate images. I

null 3.8k Dec 29, 2022
a* pathfinding algorithm written in go

astar a* (a-star) pathfinding algorithm written in go Wikipedia: EN: A* search algorithm DE: A*-Algorithmus Install go get github.com/jpierer/astar@ma

Julian Pierer 26 Mar 21, 2022
🚀 fgprof is a sampling Go profiler that allows you to analyze On-CPU as well as Off-CPU (e.g. I/O) time together.

?? fgprof - The Full Go Profiler fgprof is a sampling Go profiler that allows you to analyze On-CPU as well as Off-CPU (e.g. I/O) time together. Go's

Felix Geisendörfer 2.4k Dec 31, 2022
Spice.ai is an open source, portable runtime for training and using deep learning on time series data.

Spice.ai Spice.ai is an open source, portable runtime for training and using deep learning on time series data. ⚠️ DEVELOPER PREVIEW ONLY Spice.ai is

Spice.ai 774 Dec 15, 2022
FlyML perfomant real time mashine learning libraryes in Go

FlyML perfomant real time mashine learning libraryes in Go simple & perfomant logistic regression (~100 LoC) Status: WIP! Validated on mushrooms datas

Vadim Kulibaba 1 May 30, 2022