How to Make a Triangle in Computer Generated Art

Triangle logo

build Go Reference license release homebrew

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

Sample image

The procedure

  • Commencement the paradigm is blured out to smoth out the sharp pixel edges. The more than blured an image is the more diffused the generated output will be.
  • Second the resulted image is converted to grayscale fashion.
  • Then a sobel filter operator is applied on the grayscaled image to obtain the paradigm edges. An optional threshold value is applied to filter out the representative pixels of the resulted image.
  • A convolution filter operator is practical over the image information in gild to adjust its last aspect prior running the delaunay triangulation process.
  • Lastly the delaunay algorithm is applied on the pixels obtained from the previous stride.

Features

  • Tin process recursively whole directories and subdirectories meantime.
  • Supports various image types.
  • There is no need to specify the file type, the CLI tool tin recognize automatically the input and output file type.
  • Tin can take epitome URL equally parameter for the -in flag.
  • Possibility to salve the generated image as an SVG file.
  • The generated SVG file can exist accessed from the Spider web browser direct.
  • Clean and intuitive API. The API non just that accepts image files but can besides work with image data. This means that the Draw method can be invoked fifty-fifty on data streams. Check this demo for reference.
  • Support for pipage names (possibility to pipage in and pipe out the source and destination image).

TODO

  • Standalone and native GUI application

Caput over to this subtopic to get a ameliorate understanding of the supported features.

Installation and usage

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

You tin besides download the binary file from the releases binder.

MacOS (Brew) install

The library can be installed via Homebrew as well.

API usage

              proc              :=              &triangle.Processor{              MaxPoints:              2500,              BlurRadius:              2,              PointRate:              0.75,              BlurFactor:              1,              EdgeFactor:              vi, }              img              :=              &triangle.Image{              Processor:              *              proc, }              input,              err              :=              os.Open("input.jpg")              if              err              !=              nil              {              log.Fatalf("error opening the source file: %v",              err) }              // decode image              src,              err              :=              img.DecodeImage(input)              if              err              !=              nil              {              log.Fatalf("mistake decoding the paradigm: %5",              err) }              res,              _,              _,              err              :=              img.Draw(src,              *              proc,              func() {})              if              err              !=              zilch              {              log.Fatalf("error generating the triangles: %v",              err) }              output,              err              :=              os.Create("output.png")              if              err              !=              nil              {              log.Fatalf("fault opening the destination file: %v",              err) }              // encode image              png.Encode(output,              res)

Supported commands

The following flags are supported:

Flag Default Description
in due north/a Source image
out n/a Destination paradigm
bl 2 Blur radius
nf 0 Dissonance cistron
bf 1 Blur factor
ef 6 Edge factor
pr 0.075 Signal rate
pth x Points threshold
pts 2500 Maximum number of points
and so x Sobel filter threshold
sl imitation Use solid stroke color (aye/no)
wf 0 Wireframe way (0: without stroke, ane: with stroke, ii: stroke only)
st i Stroke width
gr false Output in grayscale mode
web imitation Open the SVG file in the web browser
bg ' ' Background color (specified as hex value)
cw system spec. Number of files to process concurrently

Cardinal features

Process multiple images from a directory concurrently

The CLI tool also let y'all process multiple images from a directory concurrently. Yous only need to provide the source and the destination folder by using the -in and -out flags.

$ triangle -in              <input_folder>              -out              <output-folder>            

Y'all tin provide as well an paradigm file URL for the -in flag.

$ triangle -in              <image_url>              -out              <output-folder>            

Pipe names

The CLI tool accepts also pipage names, which ways y'all can use stdin and stdout without the demand of providing a value for the -in and -out flag directly since these defaults to -. For this reason it's possible to use curl for instance for downloading an image from the internet and invoke the triangulation process over it directly without the need of getting the image first and calling ▲ Triangle afterwards.

Here are some examples using pipage names:

$ ringlet -south              <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 tin specify a background color in instance 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 fix the alpha channel of the resulted paradigm transparent.

Output equally 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 blazon 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 tin 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 post-obit output file types are supported: .jpg, .jpeg, .png, .bmp, .svg.

Tweaks

Setting a lower points threshold, the resulted epitome volition be more than like a cubic painting. You tin even add together 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 -st=2 -bl=2 $ triangle -in samples/input.jpg -out output.png -wf=2 -pts=5500 -st=one -bl=x

Examples

Triangle1 Triangle2 Triangle3

License

Copyright © 2018 Endre Simo

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

gaitangoome1948.blogspot.com

Source: https://github.com/esimov/triangle

0 Response to "How to Make a Triangle in Computer Generated Art"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel