## Gitee 极速下载 / Triangle .gitee-modal { width: 500px !important; }

Explore and code with more than 5 million developers，Free private repositories ！：）

Notice: Creating folder will generate an empty file .keep, because not support in Git

Triangle is a tool to generate triangulated image using delaunay triangulation. It takes a source image and converts it to an abstract image composed of tiles of triangles.

### The process

• First the image is blured out to smothen sharp pixel edges. The more blured an image is the more diffused the generated output will be.
• Second the resulted image is converted to grayscale mode.
• Then a sobel filter operator is applied on the grayscaled image to obtain the image edges. An optional threshold value is applied to filter out the representative pixels of the resulted image.
• Lastly the delaunay algorithm is applied on the pixels obtained from the previous step.
blur = tri.Stackblur(img, uint32(width), uint32(height), uint32(*blurRadius))
gray = tri.Grayscale(blur)
sobel = tri.SobelFilter(gray, float64(*sobelThreshold))
points = tri.GetEdgePoints(sobel, *pointsThreshold, *maxPoints)

triangles = delaunay.Init(width, height).Insert(points).GetTriangles()

## Installation and usage

$go get -u -f github.com/esimov/triangle/cmd/triangle$ go install

## MacOS (Brew) install

The library can be installed via Homebrew too or by downloading the binary file from the releases folder.

$brew tap esimov/triangle$ brew install triangle

### Supported commands

$triangle --help The following flags are supported: Flag Default Description in n/a Input file out n/a Output file blur 4 Blur radius pts 2500 Maximum number of points noise 0 Noise factor th 20 Points threshold sobel 10 Sobel filter threshold solid false Solid line color wf 0 Wireframe mode (without,with,both) stroke 1 Stroke width gray false Convert to grayscale web false Output SVG in browser bg ' ' Background color #### Background color You can specify a background color in case of images with a transparent background (.png) by using the -bg flag. This flag accepts a hexadecimal string value. For example setting the flag to -bg=#ffffff00 will set the alpha channel of the resulted image transparent. #### Output as image or SVG By default the output is saved to an image file, but you can export the resulted vertices even to an SVG file. The CLI tool can recognize the output type directly from the file extension. This is a handy addition for those who wish to generate large images without guality loss. $ triangle -in samples/input.jpg -out output.svg

Using with -web flag you can access the generated svg file directly on the web browser.

### Tweaks

Setting a lower points threshold, the resulted image will be more like a cubic painting. You can even add a noise factor, generating a more artistic, grainy image.

Here are some examples you can experiment with:

$triangle -in samples/input.jpg -out output.png -wf=0 -pts=3500 -stroke=2 -blur=2$ triangle -in samples/input.jpg -out output.png -wf=2 -pts=5500 -stroke=1 -blur=10

### Examples

Triangle 是使用点集三角剖分技术（delaunay triangulation technique）构建艺术图像的工具 spread retract
Go
MIT

No release