Turning my 3D-Printer into a Laser Engraver 5: Basic Slicing

With the new understanding of basically only needing two-and-a-half commands (Turning the laser on and off, moving the laser), it was time to actually turn an image into instructions to get my first real test run going.

Qt has a build in image class  QImage  which provides some good features and is apparently “designed and optimized for I/O, and for direct pixel access and manipulation” [1]. This can easily turn any image into grayscale or  black and white. When doing the latter, it also does dithering by default, that is, it simulates grayscale by mixing black and white pixels nearby. So 50% grey would alternate between black and white, which would make it look like the original grey from a sufficiently large distance. Turning dithering off would instead create a solid black blob.

Due to the very small area in which the laser actually burns, I decide against just treating the engraving plate as a map where every possible point I could burn is treated like a pixel. Instead, I work with boxes of a certain size, which I treat like pixels when processing the image for print, but actually burn in a more complicated pattern. For example, the actual plate I want to engrave has a size of 10x10cm, while the laser burns an area of around 0.1mm² at a time. The printhead can be controlled down to 0.01mm precision. To keep the time in check, I treat each area of 5x5mm as one pixel, which I call, for lack of a better term, a ‘black box’, of which the borders and diagonals will actually be burned.

This means that the source image in the example above is scaled to a 20×20 pixel pure black and white image. This resulting image is then processed in a really rather simple way:

I then went the other way around and wrote a quick script which takes the G-code as input and returns a preview of what the burned image might look like. For this cute rabbit [2], the result looks like this:

Apparently, my code flips and rotates the image. See, this is why the preview was a good idea – these kinds of errors can be fixed ahead of time.

However, actually engraving the image, in a recognizable way, actually works! (There are no interesting pictures to show, I just engraved the letter “K” in a fancy font.

Next step: Adding shades of gray and making the process much, much faster.

The full code can be found on my Github.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.