Giter VIP home page Giter VIP logo

triangler's Introduction

Works on my machine

Python Code style: black License: MIT Stargazers Twitter URL

Overview

๐Ÿ“ 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.10 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.12
$ 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] [-p POINTS] [-e {CANNY,ENTROPY,SOBEL}] [-s {POISSON_DISK,THRESHOLD}] [-r {CENTROID,MEAN}] input

positional arguments:
  input                 Input image

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output image name
  -p POINTS, --points POINTS
                        Number of sample points to use
  -e {CANNY,ENTROPY,SOBEL}, --edge-detector {CANNY,ENTROPY,SOBEL}
                        Edge detection algorithm
  -s {POISSON_DISK,THRESHOLD}, --sampler {POISSON_DISK,THRESHOLD}
                        Point sampling algorithm
  -r {CENTROID,MEAN}, --renderer {CENTROID,MEAN}
                        Color polygon rendering algorithm

API

You can use Triangler as a library.

import triangler

triangler.convert(
    img="INPUT_IMAGE.jpg",
    save_path="OUTPUT_IMAGE.jpg",
)

Sample

Effect of the number of points

Original 5000 Points
sample sample
2500 Points 1000 Points
sample sample

More samples

Original Triangler
sample sample
sample sample
sample sample

License

Licensed under the MIT License.

Copyright 2024 Donghyeok Tak

Credits

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

triangler's People

Contributors

imgbotapp avatar tdh8316 avatar wyapx 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

Watchers

 avatar  avatar  avatar

triangler's Issues

Script fails

Broken for me:

>>> triangler_instance.convert_and_save("input.jpg", "output.jpg")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/lib/python3.8/site-packages/triangler/mod.py", line 89, in convert_and_save
    im = Image.fromarray(self.convert(source).astype(np.uint8))
  File "/opt/anaconda3/lib/python3.8/site-packages/triangler/mod.py", line 58, in convert
    return process(
RuntimeWarning: Option -l or --reduce is temporarily unavailable due to the deprecated parameter multichannel of scikit-image.

numpy==1.22.4 scipy==1.8.1 requirements

Is your feature request related to a problem? Please describe.
Currently triangler requires numpy==1.22.4 scipy==1.8.1, or it won't run, but the systems I want to use it in require later versions of both numpy and scipy.

Describe the solution you'd like
Anyway you could adopt your functions to operate with more general or later versions?

error: Untyped global name 'imread': Cannot determine Numba type of <class 'function'>

Setup on macOS Ventura Apple Silicon, Python 3.11.5 venv (manually created)
installed in isolated venv using command:

python -m pip install git+https://github.com/tdh8316/triangler/

Error with PNG and JPEG:

python -m triangler -v apples.jpg   
[2024-03-13 12:50:15][INFO] in main(): Options:Namespace(images=['apples.jpg'], output=None, sample='THRESHOLD', edge='SOBEL', blur=2, color='CENTROID', points=1024, reduce=False, verbose=True)
Converting /Users/astro/github/Triangler/apples.jpg...
Process Process-1:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/astro/github/Triangler/lib/python3.11/site-packages/triangler/mod.py", line 89, in convert_and_save
    im = Image.fromarray(self.convert(source).astype(np.uint8))
                         ^^^^^^^^^^^^^^^^^^^^
  File "/Users/astro/github/Triangler/lib/python3.11/site-packages/triangler/mod.py", line 58, in convert
    return process(
           ^^^^^^^^
  File "/Users/astro/github/Triangler/lib/python3.11/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/Users/astro/github/Triangler/lib/python3.11/site-packages/numba/core/dispatcher.py", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: Literal propagation)
Failed in literal_propagation_subpipeline mode pipeline (step: performs partial type inference)
Untyped global name 'imread': Cannot determine Numba type of <class 'function'>

File "lib/python3.11/site-packages/triangler/process.py", line 30:
def process(
    <source elided>
    if isinstance(img, str):
        img = imread(img)
        ^

pip freeze output:

imageio==2.34.0
lazy_loader==0.3
llvmlite==0.42.0
networkx==3.2.1
numba==0.59.0
numpy==1.26.4
packaging==24.0
pillow==10.2.0
scikit-image==0.22.0
scipy==1.12.0
tifffile==2024.2.12
triangler @ git+https://github.com/tdh8316/triangler/@789b280a9c4fb7a593122d2dff783c82e509965f

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.