bild

package module
v0.0.0-...-c2d00d7 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: MIT Imports: 13 Imported by: 0

README

bild

bild logo

MIT License GoDoc Build Status Go Report Card

import "github.com/anthonynsimon/bild"

Simple image processing in Go with parallel processing support.

Package bild provides a collection of common image processing functions. The input images must implement the image.Image interface and the functions return an *image.RGBA.

The aim of this project is simplicity in use and development over high performance, but most algorithms are designed to be efficient and make use of parallelism when available. It is based on standard Go packages to reduce dependecy use and development abstractions.

Install

bild requires Go version 1.4 or greater.

go get -u github.com/anthonynsimon/bild

Documentation

http://godoc.org/github.com/anthonynsimon/bild

Basic example:

package main

import "github.com/anthonynsimon/bild"

func main() {
	img, err := bild.Open("filename")
	if err != nil {
		panic(err)
	}

	result := bild.Invert(img)

	if err := bild.Save("filename", result, bild.PNG); err != nil {
		panic(err)
	}
}

Output examples

Adjustment

Brightness
result := bild.Brightness(img, 0.25)

example

Contrast
result := bild.Contrast(img, -0.5)

example

Gamma
result := bild.Gamma(img, 2.2)

example

Blend modes

Add
result := bild.Add(bg, fg)

example

ColorBurn
result := bild.ColorBurn(bg, fg)

example

ColorDodge
result := bild.ColorDodge(bg, fg)

example

Darken
result := bild.Darken(bg, fg)

example

Difference
result := bild.Difference(bg, fg)

example

Divide
result := bild.Divide(bg, fg)

example

Exclusion
result := bild.Exclusion(bg, fg)

example

Lighten
result := bild.Lighten(bg, fg)

example

LinearBurn
result := bild.LinearBurn(bg, fg)

example

LinearLight
result := bild.LinearLight(bg, fg)

example

Multiply
result := bild.Multiply(bg, fg)

example

Normal
result := bild.Normal(bg, fg)

example

Opacity
result := bild.Opacity(bg, fg, 0.5)

example

Overlay
result := bild.Overlay(bg, fg)

example

Screen
result := bild.Screen(bg, fg)

example

SoftLight
result := bild.SoftLight(bg, fg)

example

Subtract
result := bild.Subtract(bg, fg)

example

Blur

BoxBlur
result := bild.BoxBlur(img, 3.0)

example

GaussianBlur
result := bild.GaussianBlur(img, 3.0)

example

Effects

EdgeDetection
result := bild.EdgeDetection(img, 1.0)

example

Emboss
result := bild.Emboss(img)

example

Grayscale
result := bild.Grayscale(img)

example

Invert
result := bild.Invert(img)

example

Median
result := bild.Median(img, 10.0)

example

Sharpen
result := bild.Sharpen(img)

example

Sobel
result := bild.Sobel(img)

example

Transform

FlipH
result := bild.FlipH(img)

example

FlipV
result := bild.FlipV(img)

example

Documentation

Overview

Package bild provides a collection of common image processing functions. The input images must implement the image.Image interface and the functions return an *image.RGBA.

The aim of this project is simplicity in use and development over high performance, but most algorithms are designed to be efficient and make use of parallelism when available. It is based on standard Go packages to reduce dependecy use and development abstractions.

Index

Constants

View Source
const (
	JPEG = iota
	PNG
)

Supported image encoding types

Variables

This section is empty.

Functions

func Add

func Add(bg image.Image, fg image.Image) *image.RGBA

Add combines the foreground and background images by adding their values and returns the resulting image.

func BoxBlur

func BoxBlur(src image.Image, radius float64) *image.RGBA

BoxBlur returns a blurred (average) version of the image. Radius must be larger than 0.

func Brightness

func Brightness(src image.Image, change float64) *image.RGBA

Brightness returns a copy of the image with the adjusted brightness. Change is the normalized amount of change to be applied (range -1.0 to 1.0).

func CloneAsRGBA

func CloneAsRGBA(src image.Image) *image.RGBA

CloneAsRGBA returns an RGBA copy of the supplied image.

func ColorBurn

func ColorBurn(bg image.Image, fg image.Image) *image.RGBA

ColorBurn combines the foreground and background images by dividing the inverted background by the foreground image and then inverting the result which is then returned.

func ColorDodge

func ColorDodge(bg image.Image, fg image.Image) *image.RGBA

ColorDodge combines the foreground and background images by dividing background by the inverted foreground image and returns the result.

func Contrast

func Contrast(src image.Image, change float64) *image.RGBA

Contrast returns a copy of the image with its difference in high and low values adjusted by the change param. Change is the normalized amount of change to be applied, in the range of -1.0 to 1.0. If Change is set to 0.0, then the values remain the same, if it's set to 0.5, then all values will be moved 50% away from the middle value.

func Convolve

Convolve applies a convolution matrix (kernel) to an image with the supplied options.

func Darken

func Darken(bg image.Image, fg image.Image) *image.RGBA

Darken combines the foreground and background images by picking the darkest value per channel for each pixel. The result is then returned.

func Difference

func Difference(bg image.Image, fg image.Image) *image.RGBA

Difference calculates the absolute difference between the foreground and background images and returns the resulting image.

func Divide

func Divide(bg image.Image, fg image.Image) *image.RGBA

Divide combines the foreground and background images by diving the values from the background by the foreground and returns the resulting image.

func EdgeDetection

func EdgeDetection(src image.Image, radius float64) *image.RGBA

EdgeDetection returns a copy of the image with it's edges highlighted.

func Emboss

func Emboss(src image.Image) *image.RGBA

Emboss returns a copy of the image in which each pixel has been replaced either by a highlight or a shadow representation.

func Encode

func Encode(w io.Writer, img image.Image, format Format) error

Encode writes an image in the specified format.

Usage example:

// Encode an image to a writer in PNG format,
// returns an error if something went wrong
err := Encode(outFile, img, bild.PNG)

func Exclusion

func Exclusion(bg image.Image, fg image.Image) *image.RGBA

Exclusion combines the foreground and background images applying the Exclusion blend mode and returns the resulting image.

func FlipH

func FlipH(img image.Image) *image.RGBA

FlipH returns a horizontally flipped version of the image.

func FlipV

func FlipV(img image.Image) *image.RGBA

FlipV returns a vertically flipped version of the image.

func Gamma

func Gamma(src image.Image, gamma float64) *image.RGBA

Gamma returns a gamma corrected copy of the image. Provided gamma param must be larger than 0.

func GaussianBlur

func GaussianBlur(src image.Image, radius float64) *image.RGBA

GaussianBlur returns a smoothly blurred version of the image using a Gaussian function. Radius must be larger than 0.

func Grayscale

func Grayscale(src image.Image) *image.RGBA

Grayscale returns a copy of the image in Grayscale using the weights 0.3R + 0.6G + 0.1B as a heuristic.

func Invert

func Invert(src image.Image) *image.RGBA

Invert returns a negated version of the image.

func Lighten

func Lighten(bg image.Image, fg image.Image) *image.RGBA

Lighten combines the foreground and background images by picking the brightest value per channel for each pixel. The result is then returned.

func LinearBurn

func LinearBurn(bg image.Image, fg image.Image) *image.RGBA

LinearBurn combines the foreground and background images by adding them and then subtracting 255 (1.0 in normalized scale). The resulting image is then returned.

func LinearLight

func LinearLight(bg image.Image, fg image.Image) *image.RGBA

LinearLight combines the foreground and background images by a mix of a Linear Dodge and Linear Burn operation. The resulting image is then returned.

func Median

func Median(img image.Image, size int) *image.RGBA

Median returns a new image in which each pixel is the median of it's neighbors. Size sets the amount of neighbors to be searched.

func Multiply

func Multiply(bg image.Image, fg image.Image) *image.RGBA

Multiply combines the foreground and background images by multiplying their normalized values and returns the resulting image.

func Normal

func Normal(bg image.Image, fg image.Image) *image.RGBA

Normal combines the foreground and background images by placing the foreground over the background using alpha compositing. The resulting image is then returned.

func Opacity

func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA

Opacity returns an image which blends the two input images by the percentage provided. Percent must be of range 0 <= percent <= 1.0

func Open

func Open(filename string) (image.Image, error)

Open loads and decodes an image from a file and returns it.

Usage example:

// Encode an image to a writer in PNG format,
// returns an error if something went wrong
img, err := Open("exampleName")

func Overlay

func Overlay(bg image.Image, fg image.Image) *image.RGBA

Overlay combines the foreground and background images by using Multiply when channel values < 0.5 or using Screen otherwise and returns the resulting image.

func Save

func Save(filename string, img image.Image, format Format) error

Save creates a file and writes to it an image in the specified format

Usage example:

// Save an image to a file in PNG format,
// returns an error if something went wrong
err := Save("exampleName", img, bild.PNG)

func Screen

func Screen(bg image.Image, fg image.Image) *image.RGBA

Screen combines the foreground and background images by inverting, multiplying and inverting the output. The result is a brighter image which is then returned.

func Sharpen

func Sharpen(src image.Image) *image.RGBA

Sharpen returns a sharpened copy of the image by detecting it's edges and adding it to the original.

func Sobel

func Sobel(src image.Image) *image.RGBA

Sobel returns an image emphasising edges using an approximation to the Sobel–Feldman operator.

func SoftLight

func SoftLight(bg image.Image, fg image.Image) *image.RGBA

SoftLight combines the foreground and background images by using Pegtop's Soft Light formula and returns the resulting image.

func Subtract

func Subtract(bg image.Image, fg image.Image) *image.RGBA

Subtract combines the foreground and background images by Subtracting the background from the foreground. The result is then returned.

Types

type ConvolutionMatrix

type ConvolutionMatrix interface {
	At(x, y int) float64
	Normalized() ConvolutionMatrix
	SideLength() int
}

ConvolutionMatrix interface. At returns the matrix value at position x, y. Normalized returns a new matrix with normalized values. SideLength returns the matrix side length.

type ConvolutionOptions

type ConvolutionOptions struct {
	Bias       float64
	Wrap       bool
	CarryAlpha bool
}

ConvolutionOptions are the Convolve function parameters. Bias is added to each RGB channel after convoluting. Range is -255 to 255. Wrap sets if indices outside of image dimensions should be taken from the opposite side. CarryAlpha sets if the alpha should be taken from the source image without convoluting

type Format

type Format int

Format is used to identify the image encoding type

type Kernel

type Kernel struct {
	Matrix []float64
	Stride int
}

Kernel to be used as a convolution matrix.

func NewKernel

func NewKernel(length int) *Kernel

NewKernel returns a kernel of the provided length.

func (*Kernel) At

func (k *Kernel) At(x, y int) float64

At returns the matrix value at position x, y.

func (*Kernel) Normalized

func (k *Kernel) Normalized() ConvolutionMatrix

Normalized returns a new Kernel with normalized values.

func (*Kernel) SideLength

func (k *Kernel) SideLength() int

SideLength returns the matrix side length.

func (*Kernel) String

func (k *Kernel) String() string

String returns the string representation of the matrix.

type RGBAF64

type RGBAF64 struct {
	R, G, B, A float64
}

RGBAF64 represents an RGBA color using the range 0.0 to 1.0 with a float64 for each channel.

func NewRGBAF64

func NewRGBAF64(r, g, b, a uint8) RGBAF64

NewRGBAF64 returns a new RGBAF64 color based on the provided uint8 values.

func (*RGBAF64) Clamp

func (c *RGBAF64) Clamp()

Clamp limits the channel values of the RGBAF64 color to the range 0.0 to 1.0.

Jump to

Keyboard shortcuts

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