GitHub - esimov/triangle: Convert images to computer art using delaunay triangul...
source link: https://github.com/esimov/triangle
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
▲ Triangle is a tool for generating 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()
Features
- Can process recursively whole directories and subdirectories concurrently.
- Supports various image types.
- There is no need to specify the file type, the CLI tool can recognize automatically the input and output file type.
- Can accept image URL as parameter for the
-in
flag. - Possibility to save the generated image as an SVG file.
- The generated SVG file can be accessed from the Web browser directly.
- Clean and intuitive API. The API not only that accepts image files but can also work with image data. This means that the
Draw
method can be invoked even on data streams. Check this demo for reference. - Support for pipe names (possibility to pipe in and pipe out the source and destination image).
Head over to this subtopic to get a better understanding of the supported features.
Installation and usage
$ go get -u -f github.com/esimov/triangle/cmd/triangle $ go install
You can also download the binary file from the releases folder.
MacOS (Brew) install
The library can be installed via Homebrew too.
$ brew install triangle
Supported commands
$ triangle --help
The following flags are supported:
Flag | Default | Description |
---|---|---|
in |
n/a | Source image |
out |
n/a | Destination image |
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 | Use solid stroke color (yes/no) |
wf |
0 | Wireframe mode (0: without stroke, 1: with stroke, 2: stroke only) |
stroke |
1 | Stroke width |
gray |
false | Output in grayscale mode |
web |
false | Open the SVG file in the web browser |
bg |
' ' | Background color (specified as hex value) |
c |
system spec. | Number of files to process concurrently (workers) |
Key features
Process multiple images from a directory concurrently
The CLI tool also let you process multiple images from a directory concurrently. You only need to provide the source and the destination folder by using the -in
and -out
flags.
$ triangle -in <input_folder> -out <output-folder>
Pipe names
The CLI tool accepts also pipe names, which means you can use stdin
and stdout
without providing a value for the -in
and -out
flag directly since these defaults to -
. For this reason is possible to use curl
for example to obtain an image from the internet and invoke the triangulation process over it directly without the need to download the image first and call ▲ Triangle afterwards.
Here are some examples using pipe names:
$ curl <image_url> | triangle > out.jpg $ cat input/source.jpg | triangle > out.jpg $ triangle -in input/source.jpg > out.jpg $ cat input/source.jpg | triangle -out out.jpg $ triangle -out out.jpg < input/source.jpg
Background color
You can specify a background color in case of transparent background images (.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.
$ triangle -in samples/input.jpg -out output.svg -web=true
Supported output types
The following output file types are supported: .jpg
, .jpeg
, .png
, .bmp
, .svg
.
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
License
Copyright © 2018 Endre Simo
This project is under the MIT License. See the LICENSE file for the full license text.
Recommend
-
88
README.md Caire is a content aware image resize library based on
-
49
-
45
README.md BezierPath + Delaunay Sample has OSBezierPath typealias to NSBezierPath and UIBezierPath. Implemented extensions to make OSBezierPath work similar/same on both platforms iOS and MacOS...
-
47
“If you have a Mac with Go and Metal, you can try this example I've just created. It renders a basic triangle that follows your mouse at 60+ FPS. #golang https://t.co/R4r5WiTbZ9”
-
59
Graph algorithms provide the means to understand, model and predict complicated dynamics such as the flow of resources or information, the pathways through which contagions or network failures spread, and the influences o...
-
47
Binance Triangle Arbitrage This app monitors the Binance cryptocurrency exchange in search of triangle arbitrage opportunities. The HUD The HUD is the chart displayed above. It...
-
11
Delaunay 四面体网格生成器 ...
-
1
Delaunay TriangleDelaunay三角剖分特点: 最小角最大:在不出现奇异性的情况下,Delaunay三角剖分最小角之和均大于任何非 Delaunay剖分所形成三角形最小角之和 ,三角形的最小内角之和最大 ,从...
-
4
-
4
Triangle Check: scan iTunes backups for traces of compromise by Operation Triangulation This script allows to scan iTunes backups for indicator of compromise by Operation Triangulation. For more information, please read
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK