Triangle is a tool to generate image arts with delaunay triangulation. It takes an input image and converts it to an abstract image composed of tiles of triangles.
- First the image is blured out to smothen the 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 resulting 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
$ triangle --help
The following flags are supported:
||2500||Maximum number of points|
||10||Sobel filter threshold|
||false||Solid line color|
||0||Wireframe mode (without,with,both)|
||false||Convert to grayscale|
||false||Save as SVG|
||false||Output SVG in browser|
Output as image or SVG
By default the output is saved to an image file, but setting the
-svg flag as
true you can export the resulted vertices even to an SVG file, being the perfect candidate for large poster images. By using a small image as input source, the
SVG export will generate an output image consuming a very low processing footprint but whitout quality loss.
$ triangle -in samples/input.jpg -out output.png -svg=1
-svg together with
-web flag you can access the svg result on the web browser.
$ triangle -in samples/input.jpg -out output.png -svg=1 -web=1
Multiple image processing with a single command
You can transform even multiple images from a specific folder with a single command by declaring as
-in flag the source folder and as
-out flag the destination folder.
$ triangle -in ./samples/ -out ./ouput -wireframe=0 -max=3500 -stroke=2 -blur=2 -noise=4
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 -wireframe=0 -max=3500 -stroke=2 -blur=2 $ triangle -in samples/input.jpg -out output.png -wireframe=2 -max=5500 -stroke=1 -blur=10
Copyright © 2018 Endre Simo
This project is under the MIT License. See the LICENSE file for the full license text.