<p>Generally, movement in a CNC, FDM-Printer, laser cutter, and Plotter has the XY plane decoupled from the Z-axis in most operations. As a result, the path in the XY plane is in 2D. But how to get to a path? Well, we have 2 variants:</p>

<h1>Pixel</h1>

<p>Most pictures store information as Pixels: each pixel on a grid has a color assigned to it. Scaling the picture does alter the grid size. These pictures are very hard to plot, unless you have your machine interpret each pixel of a given color as a specific movement operation. For example, each pixel of black color in a monochrome picture could be translated as a square-movement of a certain size, using the <strong>top-left</strong> corner of the square for the operation's reference. In G-code, drawing a line around the Pixel X=10 Y=10 with a grid size of 1 mm looks like this:</p>

<pre><code>G90 ; absolute mode!
G1 X10 Y10
G1 X1 E1
G1 Y1 E1
G1 X-1 E1
G1 Y-1 E1
</code></pre>

<h1>Vector</h1>

<p>proper 2D-Pathes are stored only in Vector graphics. If you can, Vector graphics can contain the exact path you want your machine to follow. A typical format is <code>.svg</code>. It contains already the start position of path and how to follow it. Going from Vector Graphic to G-code just needs you to add G1 before each part of the path instruction and E commands at the end to operate whatever tool you due - be it spinning the drill in a CNC, extruding filament in a printer, turning on a laser or pushing down the printhead in a plotter.</p>

CC BY-SA 4.0
2020-05-22T22:32:50.987Z
2020-05-22T22:32:50.987Z
Trish
<p>For the last 3 months I have been working on a CNC drawing machine but to this day I can't get the algorithm for line detection so I came here. </p>

<p>I can't understand only one part and it is CAM the (image to G-code) so I'd be grateful if someone could help.</p>

<p>(I want to create my own software not use any modules)</p>

CC BY-SA 4.0
2020-05-22T22:17:32.863Z
If I understand correctly, you want to write software that parses an image to G-code rather than using available software. Maybe you should explain why.
0scar
CC BY-SA 4.0
2020-05-26T12:25:41.017Z
If you slice an image, you will get gcode to create a lithophane. If you slice a 3D model, you will get gcode to create a replica of that model. What is your ultimate goal?
Davo
<cnc><python><2d>
Can't create image to G-code software for CNC to process
Irakli
# Can't create image to G-code software for CNC to process

(Asked by: username_0 on 2020-05-22)

For the last 3 months I have been working on a CNC drawing machine but to this day I can't get the algorithm for line detection so I came here.

I can't understand only one part and it is CAM the (image to G-code) so I'd be grateful if someone could help.

(I want to create my own software not use any modules)

**Tags:** cnc, python, 2d
> **Comments:**
> **username_1**: If I understand correctly, you want to write software that parses an image to G-code rather than using available software. Maybe you should explain why.  
> **username_2**: If you slice an image, you will get gcode to create a lithophane. If you slice a 3D model, you will get gcode to create a replica of that model. What is your ultimate goal?  

---

## 1 answers

### Answer by username_3 on 2020-05-22. Score: 1

Generally, movement in a CNC, FDM-Printer, laser cutter, and Plotter has the XY plane decoupled from the Z-axis in most operations. As a result, the path in the XY plane is in 2D. But how to get to a path? Well, we have 2 variants:
Pixel
Most pictures store information as Pixels: each pixel on a grid has a color assigned to it. Scaling the picture does alter the grid size. These pictures are very hard to plot, unless you have your machine interpret each pixel of a given color as a specific movement operation. For example, each pixel of black color in a monochrome picture could be translated as a square-movement of a certain size, using the top-left corner of the square for the operation's reference. In G-code, drawing a line around the Pixel X=10 Y=10 with a grid size of 1 mm looks like this:
G90 ; absolute mode!
G1 X10 Y10
G1 X1 E1
G1 Y1 E1
G1 X-1 E1
G1 Y-1 E1

Vector
proper 2D-Pathes are stored only in Vector graphics. If you can, Vector graphics can contain the exact path you want your machine to follow. A typical format is .svg. It contains already the start position of path and how to follow it. Going from Vector Graphic to G-code just needs you to add G1 before each part of the path instruction and E commands at the end to operate whatever tool you due - be it spinning the drill in a CNC, extruding filament in a printer, turning on a laser or pushing down the printhead in a plotter.


---

