An iterative algorithm to generate high quality triangulated images.

An iterative algorithm to generate high quality triangulated images.

Test status Go Reference Go Report Card License: MIT Tweet

Triangula uses a modified genetic algorithm to triangulate images. It works best with images smaller than 3000px and with fewer than 3000 points, typically producing an optimal result within a couple of minutes. For a full explanation of the algorithm, see this page in the wiki.

You can try the algorithm out in your browser here, but the desktop app will typically be 20-50x faster.

Install

GUI

Install the GUI from the releases page. The GUI uses Wails for its frontend.

If the app isn't running on Linux, go to the Permissions tab in the executable's properties and tick Allow executing file as program.

CLI

Install the CLI by running:

go get -u github.com/RH12503/Triangula-CLI/triangula

Your PATH variable also needs to include your go/bin directory, which is ~/go/bin on macOS, $GOPATH/bin on Linux, and c:\Go\bin on Windows.

Then run it using the command:

triangula run -img  -out 

and when you're happy with its fitness, render a SVG:

triangula render -in  -img  -out  

For more detailed instructions, including rendering PNGs with effects see this page.

Options

For almost all cases, only changing the number of points and leaving all other options with their default values will generate an optimal result.

Name Flag Default Usage
Points --points, -p 300 The number of points to use in the triangulation
Mutations --mutations, --mut, -m 2 The number of mutations to make
Variation --variation, -v 0.3 The variation each mutation causes
Population --population, --pop, --size 400 The population size in the algorithm
Cutoff --cutoff, --cut 5 The cutoff value of the algorithm
Cache --cache, -c 22 The cache size as a power of 2
Block --block, -b 5 The size of the blocks used when rendering
Threads --threads, -t 0 The number of threads to use or 0 to use all cores
Repetitions --reps, -r 500 The number of generations before saving to the output file (CLI only)

Examples of output

Comparison to esimov/triangle

esimov/triangle seems to be a similar project to Triangula that is also written in Go. However, the two appear to generate very different styles. One big advantage of triangle is that it generates an image almost instantaneously, while Triangula needs to run many iterations.

esimov/triangle results were taken from their Github repo, and Triangula's results were generated over 1-2 minutes.

esimov/triangle Triangula

Difference from fogleman/primitive and gheshu/image_decompiler

A lot of people have commented about Triangula's similarities to these other algorithms. While all these algorithms are iterative algorithms, the main difference is that in the other algorithms triangles can overlap while Triangula generates a triangulation.

API

Simple example:

import imageData "github.com/RH12503/Triangula/image"

func main() {
    // Open and decode a PNG/JPEG
    file, err := os.Open("image.png")

    if err != nil {
          log.Fatal(err)
    }

    image, _, err := image.Decode(file)

    file.Close()

    if err != nil {
          log.Fatal(err)
    }

    img := imageData.ToData(image)


    pointFactory := func() normgeom.NormPointGroup {
          return (generator.RandomGenerator{}).Generate(200) // 200 points
    }

    evaluatorFactory := func(n int) evaluator.Evaluator {
          // 22 for the cache size and 5 for the block size
          return evaluator.NewParallel(img, 22, 5, n)
    }

    var mutator mutation.Method

    // 1% mutation rate and 30% variation
    mutator = mutation.NewGaussianMethod(0.01, 0.3)

    // 400 population size and 5 cutoff
    algo := algorithm.NewSimple(pointFactory, 400, 5, evaluatorFactory, mutator)

    // Run the algorithm
    for {
          algo.Step()
          fmt.Println(algo.Stats().BestFitness)
    }
}

Contribute

Any contributions are welcome. Currently help is needed with:

  • Supporting more image types for the CLI and GUI. (eg. .tiff, .webp, .heic)
  • Allowing drag and drop of images from the web for the GUI.
  • More effects.
  • Any optimizations.
Comments
  • Stop button does not work if

    Stop button does not work if "Time per Frame" is set too low

    If you set "Time per Frame" to 10 or 25 and start with triangulation you are not able to stop it with the "Stop" button, because it does not react. When "Time per Frame" is set to 250 the "Stop" button works as intended.

  • Ken Thompson Image

    Ken Thompson Image

    Hi maintainers, the image of Ken Thompson that you are using cannot be included in this project under an MIT license as the underlying image is licensed under CC-BY-NC-SA. Please note that in your license docs along with proper attribution or remove it. Thanks.

  • How do I build from source?

    How do I build from source?

    Hi, I cloned this repo and ran go build and got this error:

    no Go files in C:\Users\milo5\Desktop\GitHub\triangula
    

    Any ideas on how I can build from source?

    My antivirus doesn't let me download the gui so I'm trying to self build it. Thanks!

  • Left Side of Image Appears to Have Slight Triangulation Bias

    Left Side of Image Appears to Have Slight Triangulation Bias

    This project is amazing. Thank you for building and uploading it. The outputs are remarkable and it makes computers seem like magic to me again.

    It appears Triangula is somewhat biased to render / use triangle budget on the left side of images. Parts of an image further to the left seem to resolve to better detail. Not sure if it works better to allow images to process far longer, but it seems to stop making a difference after a while.

    I don't know if this is either known, an actual issue, or helpful to you. Again, thanks for building something so cool and even... inspiring.

    Target Photo: https://en.wikipedia.org/wiki/USS_America_(CV-66)#/media/File:USS_America_(CV-66)_underway_in_the_Indian_Ocean_on_24_April_1983.jpg Dimensions: 2586 x 1769 Size: 2.11 MB Filetype: .PNG (I converted it PNG before using)

    Default Settings, 1,000 Points image

    Default Settings, 2,000 Points image

    Target Photo: https://en.wikipedia.org/wiki/Mount_Rushmore#/media/File:Mount_Rushmore_detail_view_(100MP).jpg Dimensions: 1588 x 1080 Size: 655 KB Filetype: .jpg

    Default Settings, 1,000 Points image

    Default Settings, 2,000 Points See the figure's detail on the far left (George Washington) vs the figure on the far right (Abraham Lincoln) image

  • White screen when launching GUI

    White screen when launching GUI

    I have a white screen on startup

    Screenshot_20210426_164439 Triangula version: 1.1.2 OS: Manjaro (KDE Plasma) Stdout:

    (Triangula:45221): Gtk-WARNING **: 16:44:14.988: Theme parsing error: gtk.css:73:46: The style property GtkScrolledWindow:scrollbars-within-bevel is deprecated and shouldn't be used anymore. It will be removed in a future version
    Overriding existing handler for signal 10. Set JSC_SIGNAL_FOR_GC if you want WebKit to use a different signal
    Control
    
    (WebKitWebProcess:45235): Gtk-WARNING **: 16:44:15.065: Theme parsing error: gtk.css:73:46: The style property GtkScrolledWindow:scrollbars-within-bevel is deprecated and shouldn't be used anymore. It will be removed in a future version
    
    (WebKitWebProcess:45235): Gtk-WARNING **: 16:44:15.097: Theme parsing error: gtk.css:68:35: The style property GtkButton:child-displacement-x is deprecated and shouldn't be used anymore. It will be removed in a future version
    
    (WebKitWebProcess:45235): Gtk-WARNING **: 16:44:15.097: Theme parsing error: gtk.css:69:35: The style property GtkButton:child-displacement-y is deprecated and shouldn't be used anymore. It will be removed in a future version
    
    (WebKitWebProcess:45235): Gtk-WARNING **: 16:44:15.097: Theme parsing error: gtk.css:71:36: The style property GtkCheckMenuItem:indicator-size is deprecated and shouldn't be used anymore. It will be removed in a future version
    
    (WebKitWebProcess:45235): Gtk-WARNING **: 16:44:15.097: Theme parsing error: gtk.css:73:46: The style property GtkScrolledWindow:scrollbars-within-bevel is deprecated and shouldn't be used anymore. It will be removed in a future version
    
    (WebKitWebProcess:45235): Gtk-WARNING **: 16:44:15.097: Theme parsing error: gtk.css:76:30: The style property GtkExpander:expander-size is deprecated and shouldn't be used anymore. It will be removed in a future version
    

    How to fix this?

  • --reps CLI option does not work

    --reps CLI option does not work

    Using the CLI version, it appears that the -r and --reps options are ignored, as well as the claimed default of 500 reps, since no matter whether I supply the options or not, the algorithm still proceeds beyond the supplied number and continues until killed with CTRL+C.

  • [Improvement] Add community section to Readme

    [Improvement] Add community section to Readme

    Hey Ryan,

    here's a proposal for a little community section within the readme to link to projects based on Triangula.

    Feel free to adapt the styling or to add other projects you're aware of, I started off with my own little Insta channel.

    Cheers, Fabio

  • GUI not working: blank window

    GUI not working: blank window

    Hi, i downloaded the newest release (1.1.2) from the releasepage, ran chmod +x on the unzipped file and started the application.

    A window titled "Triangula" pops up, but it's completely blank:

    image

    Console reads:

    ╰─$ ./Triangula
    Overriding existing handler for signal 10. Set JSC_SIGNAL_FOR_GC if you want WebKit to use a different signal
    Control
    

    Enviroment:

    • Linux P1 5.11.15-200.fc33.x86_64 #1 SMP Fri Apr 16 13:41:20 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
    • Fedora 33 with Mate Desktop
    • nvidia binary drivers
    • NVIDIA Quadro T1000
  • CLI and file extensions

    CLI and file extensions

    I am doing this:

    IN=schach.jpg
    JSON=fitness
    SVG=schach
    
    triangula run -img "${IN}" -out "${JSON}"
    triangula render -in "${JSON}.json" -img "${IN}" -out "${SVG}"
    

    It is a bit weird to me that "-out" on run is adding a .json file extension even if I put in "fitness.json" already. A fallback for adding the extension is nice, but imho it should check if it is supplied already (strings.HasSuffix). That way I could use $JSON for both commands in the above example.

  • Tiny controls on 4K display (Windows 10)

    Tiny controls on 4K display (Windows 10)

    Many thanks for the great project!

    However on 4K displays on Windows 10 I get veeery tiny controls ;) 2021-11-30 19_48_45-

    Size of controls doesn't change when resizing the window.

  • Allow capital file suffixes like .JPG in the file loading window

    Allow capital file suffixes like .JPG in the file loading window

    Hi, i love your programm but I have a small suggestion for improvment :-) When I want to load a new image using the GUI I can't select image files if the file suffix is in capital letters like image.JPG . I have to manually rename the file to image.jpg first. Maybe this can be fixed so that files ending with .JPG, .JPEG and .PNG can be selected too. Some Cameras and Smartphones save their images using suffixes like .JPG for some reason. Best regards, Marco

  • GUI unstoppable

    GUI unstoppable

    When I make a run within the GUI MOST of the times the application is unstoppable.

    • The stop button won't stop the run
    • The X in the window won't close
    • Even CTRL c in terminal won't halt the app
    • Only kill -9 will Fedora 35, tested on two different computers. Version 1.2.0
  • [Feature Request] Add settings about 'max generations' to automatically pause or stop.

    [Feature Request] Add settings about 'max generations' to automatically pause or stop.

    On my weak machine, the GUI application uses a lot of resources, works out of control and unstoppable. Even I can't save the generated result.

    Would you like to add a settings about "max generation in one turn" to limit generating in one click on "Start"? If the generation match max value, it will automatically pause and waits for next "Start".

  • Works great! Suggestion about referencing each other's projects

    Works great! Suggestion about referencing each other's projects

    Hi there,

    I saw your project mentioned on the Golang sub on Reddit. I knew about Wails already, but it never occurred to me that it produces such small and efficient binaries (when compared to Electron apps). I downloaded and played with your app. Great work!

    The reason I am writing this issue is because I have recently written and self-published a book about generative art in Go (https://preslav.me/generative-art-in-golang/). I thought it would be a great idea if we refer to each other's projects. There is a section in my book that I am planning to expand upon, where I refer to other nice Go projects from the same domain. I suppose, I can put yours there in a future update. You could do the same, either as part of the README or in the Wiki.

    How does that sound? Feel free to close the issue once you've read it.

    Cheers, Preslav

Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket

Features Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket Environment Variables IMAGE_SIZES - formax 200x20

Feb 2, 2022
Go-Generative-Art-A - Generate PNG art from source images! GOLang Generative Art
Go-Generative-Art-A - Generate PNG art from source images! GOLang Generative Art

GO Lang Generative Art Tool A Take source images and generate art utilizing sour

Nov 21, 2022
A phoenix Chain client based on the go-ethereum fork,the new PoS consensus engine is based on the VRF algorithm.

Phoenix Official Golang implementation of the Phoenix protocol. !!!The current version is for testing and developing purposes only!!! Building the sou

Aug 18, 2022
Read and write Netpbm images from Go programs

netpbm Introduction netpbm is a package for the Go programming language that implements image decoders and encoders for the Netpbm image formats. The

Dec 29, 2022
Pure Golang Library that allows simple LSB steganography on images
Pure Golang Library that allows simple LSB steganography on images

Steganography Lib Steganography is a library written in Pure go to allow simple LSB steganography on images. It is capable of both encoding and decodi

Dec 22, 2022
Resize images and animated GIFs in Go

Lilliput relies on mature, high-performance C libraries to do most of the work of decompressing, resizing and compressing images. It aims to do as little memory allocation as possible and especially not to create garbage in Go. As a result, it is suitable for very high throughput image resizing services.

Jan 3, 2023
Reproducing images with geometric primitives.
Reproducing images with geometric primitives.

Primitive Pictures Reproducing images with geometric primitives. How it Works A target image is provided as input. The algorithm tries to find the sin

Dec 31, 2022
Fast and secure standalone server for resizing and converting remote images

imgproxy imgproxy is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, sp

Jan 1, 2023
A go library for reading and creating ISO9660 images

iso9660 A package for reading and creating ISO9660, forked from https://github.com/kdomanski/iso9660. Requires Go 1.13 or newer. Joliet and Rock Ridge

Mar 4, 2021
A cross-platform tool to convert images into ascii art and print them on the console
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Dec 30, 2022
Convert images to computer generated art using delaunay triangulation.
Convert images to computer generated art using delaunay triangulation.

▲ Triangle is a tool for generating triangulated image using delaunay triangulation. It takes a source image and converts it to an abstract image comp

Dec 29, 2022
Emoji images for Ebiten
Emoji images for Ebiten

Ebiten Emoji Alpha version: The API is not stable yet Package emoji provides Emoji images for Ebiten. Usage func (*YourGame) Draw(screen *ebiten.Image

Dec 11, 2022
An experiment in rendering images with Slack custom emojis.
An experiment in rendering images with Slack custom emojis.

emojimage An experiment in rendering images with Slack custom emojis. Example Usage 1. Initializing your workspace First, you'll need to upload 1,332

Mar 12, 2022
a tool to output images as RGB ANSI graphics on the terminal
a tool to output images as RGB ANSI graphics on the terminal

imgcat Tool to output images in the terminal. Built with bubbletea install homebrew brew install trashhalo/homebrew-brews/imgcat prebuilt packages Pr

Dec 28, 2022
Image compression codec for 16 bit medical images

MIC - Medical Image Codec This library introduces a lossless medical image compression codec MIC for 16 bit images which provides compression ratio si

Dec 26, 2021
Small project to convert images to grayscale

This is a small http server that will read images from a provided path, convert the image to gray, and then serve back the converted image Usage You c

Nov 5, 2021
Cryptseaside generates seaside images using Unix nanoseconds as the seed value.
Cryptseaside generates seaside images using Unix nanoseconds as the seed value.

Cryptseaside Welcome to the Cryptseaside project. Cryptseaside generates seaside images using Unix nanoseconds as the seed value.

Nov 12, 2021
Repaint images by sorting pixels by colour
Repaint images by sorting pixels by colour

Every Frame A Painting Sorts pixels in an image by colour and redraws the image

Jan 5, 2022
Provides a method to create thumbnails from provided images.

Thumbnail Generation Package for Go This package provides method to create thumbnails from provided images. Installation Use to go command: $ go get g

Aug 31, 2022