Git Product home page Git Product logo

triangula's Introduction

An iterative algorithm to generate high quality triangulated and polygonal art from images.

Test status Go Reference Go Report Card License: MIT Tweet

Triangula uses a modified genetic algorithm to triangulate or polygonate 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 <path to image> -out <path to output JSON>

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

triangula render -in <path to outputted JSON> -img <path to image> -out <path to output SVG> 

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

Triangulated

Polygonal

Community Examples

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

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
          // use PolygonsImageFunctions for polygons 
		  return evaluator.NewParallel(fitness.TrianglesImageFunctions(imgData, 5, n), 22)
    }

    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.NewModifiedGenetic(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:

  • Support for exporting effects to SVGs.
  • 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.

Thank you to these contributors for helping to improve Triangula:

triangula's People

Contributors

fabiomai avatar precelerator avatar rh12503 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

triangula's Issues

Cannot install go package due to capitalization in mod.go

Hi! I'd like to try your application but could not installed it locally on Fedora 38:

$ go install github.com/rh12503/triangula-cli/triangula@latest
go: github.com/rh12503/triangula-cli/triangula@latest: github.com/rh12503/[email protected]: parsing go.mod:
	module declares its path as: github.com/RH12503/Triangula-CLI
	        but was required as: github.com/rh12503/triangula-cli

I hope fixing the capitalization fixes this issue. Also, if it works, it'd be nice to adjust the README.md to use "install" instead of "get".

Cheers,
Maximilian.

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.

--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.

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?

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!

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.

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".

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

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.

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?

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

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.