triangle

Convert images to computer generated art using delaunay triangulation.

Github星跟蹤圖

Triangle logo

Build Status
GoDoc
license
release
homebrew

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.

Sample image

The technique

  • 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

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, max, 2500, Maximum number of points, noise, Noise factor, points, 20, Points threshold, sobel, 10, Sobel filter threshold, solid, false, Solid line color, wireframe, Wireframe mode (without,with,both), stroke, 1, Stroke width, gray, false, Convert to grayscale, web, false, Output SVG in browser, #### 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.

$ triangle -in samples/input.jpg -out output.svg -web=true

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

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 -wireframe=0 -max=3500 -stroke=2 -blur=2
$ triangle -in samples/input.jpg -out output.png -wireframe=2 -max=5500 -stroke=1 -blur=10

Examples





Sample_0
Sample_1
Sample_11
Sample_8

License

Copyright © 2018 Endre Simo

This project is under the MIT License. See the LICENSE file for the full license text.

主要指標

概覽
名稱與所有者esimov/triangle
主編程語言Go
編程語言Go (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2017-08-26 04:24:31
推送於2024-10-24 06:51:49
最后一次提交2024-10-24 09:51:49
發布數17
最新版本名稱v2.0.0 (發布於 2022-04-20 13:01:22)
第一版名稱v1.0.0 (發布於 2017-09-28 14:24:40)
用户参与
星數2k
關注者數26
派生數110
提交數245
已啟用問題?
問題數17
打開的問題數1
拉請求數8
打開的拉請求數1
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?