Documentation ¶
Overview ¶
Package triangle is an image processing library which converts images to computer generated art using delaunay triangulation.
The package provides a command line utility supporting various customization options. Check the supported commands by typing:
$ triangle --help
Using Go interfaces the API can expose the result either as raster or vector type.
Example to generate triangulated image and output the result as raster type:
package main import ( "fmt" "github.com/esimov/triangle" ) func main() { p := &triangle.Processor{ // Initialize struct variables } img := &triangle.Image{*p} _, _, err = img.Draw(file, fq, func() {}) if err != nil { fmt.Printf("Error on triangulation process: %s", err.Error()) } }
Example to generate triangulated image and output the result as SVG:
package main import ( "fmt" "github.com/esimov/triangle" ) func main() { p := &triangle.Processor{ // Initialize struct variables } svg := &triangle.SVG{ Title: "Delaunay image triangulator", Lines: []triangle.Line{}, Description: "Convert images to computer generated art using delaunay triangulation.", StrokeWidth: p.StrokeWidth, StrokeLineCap: "round", //butt, round, square Processor: *p, } _, _, err = svg.Draw(file, fq, func() { // Call the closure function }) if err != nil { fmt.Printf("Error on triangulation process: %s", err.Error()) } }
Index ¶
- Constants
- func Grayscale(src *image.NRGBA) *image.NRGBA
- func Noise(amount int, pxl image.Image, w, h int) *image.NRGBA64
- func SobelFilter(img *image.NRGBA, threshold float64) *image.NRGBA
- func StackBlur(img *image.NRGBA, radius uint32) *image.NRGBA
- func ToNRGBA(img image.Image) *image.NRGBA
- type Delaunay
- type Drawer
- type Fn
- type Image
- type Line
- type Node
- type Point
- type Processor
- type SVG
- type Triangle
Constants ¶
const ( // WithoutWireframe - generates triangles without stroke WithoutWireframe = iota // WithWireframe - generates triangles with stroke WithWireframe // WireframeOnly - generates triangles only with wireframe WireframeOnly )
const PointRate = 0.875
PointRate defines the default point rate. Changing this value will modify the triangles sizes.
Variables ¶
This section is empty.
Functions ¶
func Noise ¶
Noise apply a noise factor, like adobe's grain filter to create a despeckle like image.
func SobelFilter ¶
SobelFilter uses the sobel threshold operator to detect the image edges. See https://en.wikipedia.org/wiki/Sobel_operator
Types ¶
type Delaunay ¶
type Delaunay struct {
// contains filtered or unexported fields
}
Delaunay defines the main components of the triangulation.
func (*Delaunay) GetTriangles ¶
GetTriangles returns the generated triangles.
type Drawer ¶ added in v1.0.2
type Drawer interface {
Draw(interface{}, interface{}, Fn) (image.Image, []Triangle, []Point, error)
}
Drawer interface defines the Draw method. This has to be implemented by every struct which declares a Draw method. By using this method the image can be triangulated as raster type or SVG.
type Image ¶ added in v1.0.2
type Image struct {
Processor
}
Image extends the Processor struct.
func (*Image) Draw ¶ added in v1.0.2
func (im *Image) Draw(input interface{}, output interface{}, fn Fn) (image.Image, []Triangle, []Point, error)
Draw is an interface method which triangulates the source type and outputs the result even to an image or a pixel data. The input could be an image file or a pixel data. This is the reason why interface is used as argument type. It returns the number of triangles generated, the number of points and the error in case exists.
type Node ¶
type Node struct {
X, Y int
}
Node defines a struct having as components the node X and Y coordinate position.
type Processor ¶ added in v1.0.1
type Processor struct { BlurRadius int SobelThreshold int PointsThreshold int MaxPoints int Wireframe int Noise int StrokeWidth float64 IsStrokeSolid bool Grayscale bool OutputToSVG bool ShowInBrowser bool BgColor string }
Processor encompasses all of the currently supported processing options.
type SVG ¶ added in v1.0.2
type SVG struct { Width int Height int Title string Lines []Line Color color.RGBA Description string StrokeLineCap string StrokeWidth float64 Processor }
SVG extends the Processor struct with the SVG parameters.
func (*SVG) Draw ¶ added in v1.0.2
func (svg *SVG) Draw(input interface{}, output interface{}, fn Fn) (image.Image, []Triangle, []Point, error)
Draw triangulates the source image and outputs the result to an SVG file. It has the same method signature as the rester Draw method, only that accepts a callback function for further processing, like opening the generated SVG file in the web browser. Everyone can define it's own callback function, depending on each one personal needs. It returns the number of triangles generated, the number of points and the error in case exists.