triangle

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2018 License: MIT Imports: 9 Imported by: 5

README

Triangle is a tool to create image arts using the delaunay triangulation technique. It takes an image as input and it converts to 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 we apply the delaunay algorithm 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 github.com/esimov/triangle/cmd/triangle
$ go install
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 0 Noise factor
points 20 Points threshold
sobel 10 Sobel filter threshold
solid false Solid line color
wireframe 0 Wireframe mode (without,with,both)
width 1 Wireframe line width
gray false Convert to grayscale

Setting a lower points value, the resulted image will be more like a cubic painting. You can even add a noise factor, giving a more artistic, despeckle like result for the final image.

In case the gray filter is set as true the resulting triangulated image will be converted to grayscale mode.

Here are some examples you can experiment with:

$ triangle -in samples/clown_4.jpg -out output.png -wireframe=0 -max=3500 -width=2 -blur=2
$ triangle -in samples/clown_4.jpg -out output.png -wireframe=2 -max=5500 -width=1 -blur=10

You can even transform multiple images from a specific folder with one command, concurently, by specifying as -in flag the source folder and as -out flag the destination folder. Example:

$ triangle -in ./samples/ -out ./ouput -wireframe=0 -max=3500 -width=2 -blur=2 -noise=4

Below are some of the generated images:

Sample_0 Sample_1 Sample_11 Sample_8

License

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

Documentation

Index

Constants

View Source
const (
	WITHOUT_WIREFRAME = iota
	WITH_WIREFRAME
	WIREFRAME_ONLY
)
View Source
const POINT_RATE = 0.875

Variables

This section is empty.

Functions

func Grayscale

func Grayscale(src *image.NRGBA) *image.NRGBA

Convert image to grayscale.

func Noise

func Noise(amount int, pxl image.Image, w, h int) *image.NRGBA64

Apply a noise factor, like adobe's grain filter

func SobelFilter

func SobelFilter(img *image.NRGBA, threshold float64) *image.NRGBA

Detect image edges. See https://en.wikipedia.org/wiki/Sobel_operator

func Stackblur

func Stackblur(img *image.NRGBA, width, height, radius uint32) *image.NRGBA

Types

type Delaunay

type Delaunay struct {
	// contains filtered or unexported fields
}

func (*Delaunay) GetTriangles

func (d *Delaunay) GetTriangles() []Triangle

Get the generated triangles.

func (*Delaunay) Init

func (d *Delaunay) Init(width, height int) *Delaunay

func (*Delaunay) Insert

func (d *Delaunay) Insert(points []Point) *Delaunay

Insert new triangles into the delaunay triangles slice.

type Node

type Node struct {
	X, Y int
}

type Point

type Point struct {
	// contains filtered or unexported fields
}

func GetEdgePoints

func GetEdgePoints(img *image.NRGBA, threshold, maxPoints int) []Point

Get the edge points after the Sobel filter has been applied.

type Processor added in v1.0.1

type Processor struct {
	BlurRadius      int
	SobelThreshold  int
	PointsThreshold int
	MaxPoints       int
	Wireframe       int
	Noise           int
	LineWidth       float64
	IsSolid         bool
	Grayscale       bool
}

Processor : type with processing options

func (*Processor) Process added in v1.0.1

func (p *Processor) Process(file io.Reader, output string) (*os.File, []Triangle, []Point, error)

Process : Triangulate the source image

type Triangle

type Triangle struct {
	Nodes []Node
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL