triangler icon indicating copy to clipboard operation
triangler copied to clipboard

:triangular_ruler: Convert images to Low-Poly art using Delaunay triangulation.

Works on my machine

Python Code style: black License: MIT Stargazers Twitter URL

Overview

:triangular_ruler: Convert images to Low-Poly art using Delaunay triangulation.

sample

Table of contents

  1. Installation
  2. Usage
  3. Use as a library
  4. Sample
  5. License

Installation

You need Python 3.6 or higher.

I strongly recommend to use virtual environment such as Anaconda. You can download Anaconda here.

Follow manual below to create python virtual environment for Triangler with the Anaconda.

$ conda create -n triangler python=3.8
$ activate triangler
(triangler)$ python -m pip install git+https://github.com/tdh8316/triangler/

Usage

(triangler)$ python -m triangler -h
usage: __main__.py [-h] [-o OUTPUT [OUTPUT ...]] [-s {POISSON_DISK,THRESHOLD}]
                   [-e {CANNY,ENTROPY,SOBEL}] [-b BLUR] [-c {MEAN,CENTROID}]
                   [-p POINTS] [-l REDUCE] [-v]
                   images [images ...]

positional arguments:
  images                Source files

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT [OUTPUT ...], --output OUTPUT [OUTPUT ...]
                        Destination file (default: None)
  -s {POISSON_DISK,THRESHOLD}, --sample {POISSON_DISK,THRESHOLD}
                        Sampling method for candidate points. (default: THRESHOLD)
  -e {CANNY,ENTROPY,SOBEL}, --edge {CANNY,ENTROPY,SOBEL}
                        Pre-processing method to use. (default: SOBEL)
  -b BLUR, --blur BLUR  Blur radius for approximate canny edge detector.
                        (default: 2)
  -c {MEAN,CENTROID}, --color {MEAN,CENTROID}
                        Coloring method for rendering. (default: CENTROID)
  -p POINTS, --points POINTS
                        Points threshold. (default: 1024)
  -l, --reduce          Apply pyramid reduce to result image (default: False)
  -v, --verbose         Set logger level as DEBUG (default: False)

The POISSON_DISK sampling option is slow, while it can provide the best result.

You can see the results by options here.

It takes a minimum of 5 seconds (1000 points and threshold sampling) to a maximum of 2 minutes (10000 points and poisson disk sampling).

API

See example code:

import triangler

# Create Triangler instance
triangler_instance = triangler.Triangler(
    # TODO: Customize these arguments
    # edge_method=EdgeMethod.SOBEL,
    # sample_method=SampleMethod.THRESHOLD,
    # color_method=ColorMethod.CENTROID,
    # points=1000,
    # blur=2,
    # pyramid_reduce=True,
)

# Convert and save as an image
triangler_instance.convert_and_save("INPUT_PATH", "OUTPUT_PATH")

Sample

Original 5000 Points
sample sample
2500 Points 1000 Points
sample sample
Original Processed
sample sample
sample sample
sample sample

License

Licensed under the MIT License.

Copyright 2022 Donghyeok Tak

Special thanks

Some algorithms, including the Poisson disk sampling, are based on pmaldonado/PyTri.