Giter Club home page Giter Club logo

image-to-gcode's Introduction

Image to G-code converter

This repository contains a Python 3 script that takes an image as input and generates a 2D G-code file as output. The script can either use the provided image as an edges image, or auto-detect the edges using the Sobel operator. Then a graph is built and it is converted to G-code. You can then use the produced G-code in a 2D plotter, you may find this other project of mine useful: plotter.

Auto-detecting edges Considering image as already edges
Obtained with http://jherrm.com/gcode-viewer/

Usage

You can run the script normally with Python 3:

python3 image_to_gcode.py ARGUMENTS...

This is the help screen with all valid arguments (obtainable with python3 image_to_gcode.py --help):

usage: image_to_gcode.py [-h] -i FILE -o FILE [--dot-output FILE] [-e MODE] [-t VALUE]

Detects the edges of an image and converts them to 2D gcode that can be printed by a plotter

optional arguments:
  -h, --help            show this help message and exit
  -i FILE, --input FILE
                        Image to convert to gcode; all formats supported by the Python imageio library are supported
  -o FILE, --output FILE
                        File in which to save the gcode result
  --dot-output FILE     Optional file in which to save the graph (in DOT format) generated during an intermediary step of gcode generation
  -e MODE, --edges MODE
                        Consider the input file already as an edges matrix, not as an image of which to detect the edges. MODE should be either `white` or `black`, that is the color of the edges in the image. The image should only be made of white or black pixels.
  -t VALUE, --threshold VALUE
                        The threshold in range (0,255) above which to consider a pixel as part of an edge (after Sobel was applied to the image or on reading the edges from file with the --edges option)

The required parameters are the input and the output. You may want to tune the threshold value in order to obtain a better graph.

An example of command is:

python3 image_to_gcode.py --input image.png --output graph.nc --threshold 100

image-to-gcode's People

Contributors

stypox avatar

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.