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
- func Add(bg image.Image, fg image.Image) *image.RGBA
- func BoxBlur(src image.Image, radius float64) *image.RGBA
- func Brightness(src image.Image, change float64) *image.RGBA
- func CloneAsRGBA(src image.Image) *image.RGBA
- func ColorBurn(bg image.Image, fg image.Image) *image.RGBA
- func ColorDodge(bg image.Image, fg image.Image) *image.RGBA
- func Contrast(src image.Image, change float64) *image.RGBA
- func Convolve(img image.Image, k ConvolutionMatrix, o *ConvolutionOptions) *image.RGBA
- func Darken(bg image.Image, fg image.Image) *image.RGBA
- func Difference(bg image.Image, fg image.Image) *image.RGBA
- func Divide(bg image.Image, fg image.Image) *image.RGBA
- func EdgeDetection(src image.Image, radius float64) *image.RGBA
- func Emboss(src image.Image) *image.RGBA
- func Encode(w io.Writer, img image.Image, format Format) error
- func Exclusion(bg image.Image, fg image.Image) *image.RGBA
- func FlipH(img image.Image) *image.RGBA
- func FlipV(img image.Image) *image.RGBA
- func Gamma(src image.Image, gamma float64) *image.RGBA
- func GaussianBlur(src image.Image, radius float64) *image.RGBA
- func Grayscale(src image.Image) *image.RGBA
- func Invert(src image.Image) *image.RGBA
- func Lighten(bg image.Image, fg image.Image) *image.RGBA
- func LinearBurn(bg image.Image, fg image.Image) *image.RGBA
- func LinearLight(bg image.Image, fg image.Image) *image.RGBA
- func Median(img image.Image, size int) *image.RGBA
- func Multiply(bg image.Image, fg image.Image) *image.RGBA
- func Normal(bg image.Image, fg image.Image) *image.RGBA
- func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA
- func Open(filename string) (image.Image, error)
- func Overlay(bg image.Image, fg image.Image) *image.RGBA
- func Save(filename string, img image.Image, format Format) error
- func Screen(bg image.Image, fg image.Image) *image.RGBA
- func Sharpen(src image.Image) *image.RGBA
- func Sobel(src image.Image) *image.RGBA
- func SoftLight(bg image.Image, fg image.Image) *image.RGBA
- func Subtract(bg image.Image, fg image.Image) *image.RGBA
- type ConvolutionMatrix
- type ConvolutionOptions
- type Format
- type Kernel
- type RGBAF64
Constants ¶
const ( JPEG = iota PNG )
Supported image encoding types
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add combines the foreground and background images by adding their values and returns the resulting image.
func BoxBlur ¶
BoxBlur returns a blurred (average) version of the image. Radius must be larger than 0.
func Brightness ¶
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 ¶
CloneAsRGBA returns an RGBA copy of the supplied image.
func ColorBurn ¶
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 ¶
ColorDodge combines the foreground and background images by dividing background by the inverted foreground image and returns the result.
func Contrast ¶
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 ¶
func Convolve(img image.Image, k ConvolutionMatrix, o *ConvolutionOptions) *image.RGBA
Convolve applies a convolution matrix (kernel) to an image with the supplied options.
func Darken ¶
Darken combines the foreground and background images by picking the darkest value per channel for each pixel. The result is then returned.
func Difference ¶
Difference calculates the absolute difference between the foreground and background images and returns the resulting image.
func Divide ¶
Divide combines the foreground and background images by diving the values from the background by the foreground and returns the resulting image.
func EdgeDetection ¶
EdgeDetection returns a copy of the image with it's edges highlighted.
func Emboss ¶
Emboss returns a copy of the image in which each pixel has been replaced either by a highlight or a shadow representation.
func Encode ¶
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 ¶
Exclusion combines the foreground and background images applying the Exclusion blend mode and returns the resulting image.
func Gamma ¶
Gamma returns a gamma corrected copy of the image. Provided gamma param must be larger than 0.
func GaussianBlur ¶
GaussianBlur returns a smoothly blurred version of the image using a Gaussian function. Radius must be larger than 0.
func Grayscale ¶
Grayscale returns a copy of the image in Grayscale using the weights 0.3R + 0.6G + 0.1B as a heuristic.
func Lighten ¶
Lighten combines the foreground and background images by picking the brightest value per channel for each pixel. The result is then returned.
func LinearBurn ¶
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 ¶
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 ¶
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 ¶
Multiply combines the foreground and background images by multiplying their normalized values and returns the resulting image.
func Normal ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Sharpen returns a sharpened copy of the image by detecting it's edges and adding it to the original.
func Sobel ¶
Sobel returns an image emphasising edges using an approximation to the Sobel–Feldman operator.
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 ¶
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 Kernel ¶
Kernel to be used as a convolution matrix.
func (*Kernel) Normalized ¶
func (k *Kernel) Normalized() ConvolutionMatrix
Normalized returns a new Kernel with normalized values.
func (*Kernel) SideLength ¶
SideLength returns the matrix side length.
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 ¶
NewRGBAF64 returns a new RGBAF64 color based on the provided uint8 values.