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 Crop(img image.Image, rect image.Rectangle) *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 ExtractChannel(img image.Image, c Channel) *image.Gray
- 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(img image.Image) *image.Gray
- 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 NormalBlend(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 Resize(img image.Image, width, height int, filter ResampleFilter) *image.RGBA
- func Rotate(img image.Image, angle float64, options *RotationOptions) *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
- func Threshold(img image.Image, level uint8) *image.Gray
- type Channel
- type ConvolutionMatrix
- type ConvolutionOptions
- type Format
- type Histogram
- type Kernel
- type RGBAF64
- type RGBAHistogram
- type ResampleFilter
- type RotationOptions
Constants ¶
const ( Red = iota Green Blue Alpha )
Channel identifiers
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.
Usage example:
result := Convolve(img, kernel, &ConvolutionOptions{Bias: 0, Wrap: false, CarryAlpha: false})
func Crop ¶
Crop returns a new image which contains the intersection between the rect and the image provided as params. Only the intersection is returned. If a rect larger than the image is provided, no fill is done to the 'empty' area.
Usage example:
result := bild.Crop(img, image.Rect(0,0,512,256))
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 ExtractChannel ¶
ExtractChannel returns a grayscale image containing the values of the selected channel. Channel indices Red: '0', Green: '1', Blue: '2', Alpha: '3'.
Usage example:
result := bild.ExtractChannel(img, bild.Alpha)
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 NormalBlend ¶
NormalBlend 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 Resize ¶
Resize returns a new image with its size adjusted to the new width and height. The filter param corresponds to the Resampling Filter to be used when interpolating between the sample points.
Usage example:
result := bild.Resize(img, 800, 600, bild.Linear)
func Rotate ¶
Rotate returns a rotated image by the provided angle using the pivot as an anchor. Parameters angle is in degrees and it's applied clockwise. Default parameters are used if a nil *RotationOptions is passed.
Usage example:
// Rotate 90.0 degrees clockwise, preserving the image size and the pivot point at the top left corner result := bild.Rotate(img, 90.0, &bild.RotationOptions{PreserveSize: true, Pivot: &image.Point{0, 0}})
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.
func SoftLight ¶
SoftLight combines the foreground and background images by using Pegtop's Soft Light formula and returns the resulting image.
Types ¶
type ConvolutionMatrix ¶
type ConvolutionMatrix interface { At(x, y int) float64 Normalized() ConvolutionMatrix MaxX() int MaxY() int }
ConvolutionMatrix interface. At returns the matrix value at position x, y. Normalized returns a new matrix with normalized values. MaxX returns the horizontal length. MaxY returns the vertical 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 Histogram ¶
type Histogram struct {
Bins []int
}
Histogram holds a variable length slice of bins, which keeps track of sample counts.
func (*Histogram) Cumulative ¶
Cumulative returns a new Histogram in which each bin is the cumulative value of it's previous bins
func (*Histogram) Image ¶
Image returns a grayscale image representation of the Histogram. The width and height of the image will be equivalent to the number of Bins in the Histogram.
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.
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.
type RGBAHistogram ¶
RGBAHistogram holds a sub-histogram per RGBA channel. Each channel histogram contains 256 bins (8-bit color depth per channel).
func NewRGBAHistogram ¶
func NewRGBAHistogram(img image.Image) *RGBAHistogram
NewRGBAHistogram constructs a RGBAHistogram out of the provided image. A sub-histogram is created per RGBA channel with 256 bins each.
func (*RGBAHistogram) Cumulative ¶
func (h *RGBAHistogram) Cumulative() *RGBAHistogram
Cumulative returns a new RGBAHistogram in which each bin is the cumulative value of it's previous bins per channel.
func (*RGBAHistogram) Image ¶
func (h *RGBAHistogram) Image() *image.RGBA
Image returns an RGBA image representation of the RGBAHistogram. An image width of 256 represents the 256 Bins per channel and the image height of 256 represents the max normalized histogram value per channel. Each RGB channel from the histogram is mapped to its corresponding channel in the image, so that for example if the red channel is extracted from the image, it corresponds to the red channel histogram.
type ResampleFilter ¶
ResampleFilter is used to evaluate sample points and interpolate between them. Support is the number of points required by the filter per 'side'. For example, a support of 1.0 means that the filter will get pixels on positions -1 and +1 away from it. Fn is the resample filter function to evaluate the samples.
var Box ResampleFilter
Box resampling filter, only let pass values in the x < 0.5 range from sample. It produces similar results to the Nearest Neighbor method.
var CatmullRom ResampleFilter
CatmullRom resampling filter interpolates between the four nearest samples per dimension.
var Gaussian ResampleFilter
Gaussian resampling filter interpolates using a Gaussian function between the two nearest samples per dimension.
var Lanczos ResampleFilter
Lanczos resampling filter interpolates between the six nearest samples per dimension.
var Linear ResampleFilter
Linear resampling filter interpolates linearly between the two nearest samples per dimension.
var MitchellNetravali ResampleFilter
MitchellNetravali resampling filter interpolates between the four nearest samples per dimension.
var NearestNeighbor ResampleFilter
NearestNeighbor resampling filter assigns to each point the sample point nearest to it.
type RotationOptions ¶
RotationOptions are the rotation parameters ResizeBounds set to false will keep the original image bounds, cutting any pixels that go past it when rotating. Pivot is the point of anchor for the rotation. Default of center is used if a nil is passed. If ResizeBounds is set to true, a center pivot will always be used.