Project:LayserCake

From London Hackspace Wiki
(Redirected from Projects/LayserCake)

http://hack.rs/cgi-bin/threshold_grayscale.pl

Hello lovely people. A while ago there was formed the a plan to take detailed images and split them inyo bitplane layers to allow our laser cutter to efficiently engrave 256 shades of grey. AndyE wrote the perl script (see source below) and uploaded it to Babbage for your engraving pleasure.

So hie yourself to the following URL, and feed it the image you'd like to engrave grayscale styl-E http://hack.rs/cgi-bin/threshold_grayscale.pl

This does not support colour engraving with the laser. Anyone believing that it does will be offered a cup of tea, a lie down and a brief course on basic physics.

People


How-to - a worked example

Let's say you have this charming picture of a cake to begin with:

220px-Strawberry Cake.JPG

So you feed it to the script at the URL at the top of this page, and the script will give you back 8 files numbered 0 to 7. Determine what strength/speed you'd engrave your material at.

That will give you 8 images, import them into the laser cutter software, align them on top of each other and set them all to be different engraving layers (colours)

Lase number 7 at 50% of that power (50% of whatever full engrave strength should be for your material).

220px-Strawberry Cake 7.JPG

Then lase number 6 at 25% power:

220px-Strawberry Cake 6.JPG

Then number 5 at 12.5% power:

220px-Strawberry Cake 5.JPG

and so on and so on, halving the power each time.

4

220px-Strawberry Cake 4.JPG

3

220px-Strawberry Cake 3.JPG

2

220px-Strawberry Cake 2.JPG

1

220px-Strawberry Cake 1.JPG

0

220px-Strawberry Cake 0.JPG

Each sucessive engrave adds a little extra detail to the image.

Then report back here to let us know how it went!

An alternative would be to double the speed each time, rather than halving the power. Would be interesting to see tests for both methods on the same image.

What we expect Engraved Wood should exhibit a discernable shading, showing light and dark areas of engraving.

Engraved acrylic should show definite depth differences with the depth of engraving at any point corresponding to the brightness of the image at that point.


How it went

First attempt was burnt black and actually holed through the 3mm MDF. not a good start

Second attempt worked rather better as you can see.

GreyscalecakeBurn.jpg

It's not a good greyscale, but the depth of burn is pretty solidly proportional to the brightness of the image.

Next steps

cool - that's a start. what settings did you use for that one? --AndyE 18:34, 16 January 2011 (UTC)

Source

People on IRC expressed a wish to use this as an example for security auditing, so here it is. Will transfer it to git when I 'git' time.

Audit away.

Please don't make me cry.

--AndyE 13:00, 13 January 2011 (UTC)


#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
#use List::Util qw(max min);

my $q = CGI->new();

print $q->header;
print $q->start_html;

print $q->p("this is a thing for doing threshholding");
print $q->p("<small>or possibly <i>thresholding</i>?</small>");

print $q->start_form( -enctype => "multipart/form-data" );

print $q->p("file");
print $q->filefield('uploaded_file');
print $q->submit();

print $q->end_form;

# do we have an upload?
my $filehandle = $q->upload('uploaded_file');
if (defined $filehandle) {

    # do shit
    print $q->p("I'm doing shit");

    # no, actually do shit
    my ($filename, $extension) = ($q->param('uploaded_file') =~ /^([0-9A-Za-z_-]+)\.([0-9A-Za-z_-]+)$/);
    die "no stupid filenames" unless ($filename and $extension);
    my $tempfile = $q->tmpFileName($q->param('uploaded_file'));

    foreach my $i (0 .. 7) {

        my $n = 2 ** $i;

        my $outfile = "$filename"."_$i.$extension";

        my @ar = ("gm",
                  "convert",
                    "-operator", "Gray", "And", $n ,
                    "-operator", "Gray", "Threshold",  $n - 1  ,
                  $tempfile,
                  "/var/www/threshold_output/$outfile" );

        print $q->p("$i : " . join " ", @ar);

        system(@ar) == 0 or die "system call failed: $? $!"; #safer than passing a string to system(),
                                                             # because doing it this way bypasses the shell

        print $q->img({src => "/threshold_output/$outfile"});
    }
}


print $q->end_html;