586,094 active members*
4,177 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 22
  1. #1
    Join Date
    Nov 2004
    Posts
    27

    Image (Greyscale) to GCODE

    Hehe! I have just made a small program that makes gcode of greyscale or B&W images. It is not yet finished, as I don't yet have a CNC mill, but you are welcome to use it and alter or redistribute it, if you find it useful.

    It's written in PHP and takes image.png as the image file. Also $x_max, $y_max and $z_max are set to set the image size when carved. I haven't yet found a way for the image not to be mirrored and also there are no way of choosing milling diameter or steps. But look at it, use it and see what you can do:


    Mind that all the "n"'s should be preceded by a backslash... Also there might be other small stuff lost in the conversion to this post.

    HTML Code:
    <?php
    
    $file = "image.png";
    $im = imagecreatefrompng($file);
    $size_arr = getimagesize($file);
    
    $x_max = 800;
    $x_factor = $size_arr&#91;0&#93;;
    
    $y_max = 800;
    $y_factor = $size_arr&#91;1&#93;;
    
    $z_max = 40;
    $z_factor = 256;
    
    $last_x = 0;
    $last_y = 0;
    $last_z = 0;
    
    echo "G01 X0 Y0 Z0\n";
    
    for ($y=$size_arr&#91;1&#93;; $y>0; $y--) {
       for ($x=0; $x<$size_arr&#91;0&#93;; $x++) {
           $rgb = ImageColorAt($im, $x, $y);
           $z = $rgb;
           $x_pos = ($x/$x_factor*$x_max);
           $y_pos = ($y/$y_factor*$y_max);
           $z_pos = -($z/$z_factor*$z_max);
    
           echo "G01";
           if ($x_pos != $last_x){
                    echo " X".$x_pos;
                    $last_x = $x_pos;
            }
           if ($y_pos != $last_y){
                    echo " Y".$y_pos;
                    $last_y = $y_pos;
            }
           if ($z_pos != $last_z){
                    echo " Z".$z_pos;
                    $last_z = $z_pos;
            }
    
           echo "\n";
       }
    }
    
    ?>

  2. #2
    Join Date
    Nov 2004
    Posts
    27

    Oh, forgot!

    Forgot to say, that Gcode output might not be 100% compliant, but it works in CNCSimulator...

  3. #3
    Join Date
    Feb 2005
    Posts
    124
    Hi,

    I think I'm the first one who tests your software...

    I'm also a php programmer. Your code seems to loop very long and I think there are still some errors.

    When testing a sample picture I get a Z of: Z-2621439.84375

    Shouldn't be correct so I won't test it on my machine yet.

  4. #4
    Join Date
    Aug 2004
    Posts
    3215
    Any new development of this code? I'm not a programer but looking for something for pictures to engrave, Not for buiseness but personal so cost is an issue. and just wondering how this works?

    Thanks, Joe

  5. #5
    Join Date
    Jun 2005
    Posts
    55
    Joe,

    Email me, I'm working on something cool and opensource.
    Check out my user (rherman) gallery on this site for pics.

    Rob

  6. #6
    Join Date
    Jun 2005
    Posts
    1
    Rob,
    I'm interested in your Gcode program
    that generates a numeric grid of your grey-scale image files.
    [email protected]

  7. #7
    Join Date
    Jun 2005
    Posts
    55
    Still working on it! I'll only release it when it is further along. I'll let you know. Thanks.

    Rob

  8. #8
    Join Date
    Jun 2005
    Posts
    90

    Wow!!! Cool!!!

    I'm interested (VERY)... I'd like to try/test it.

    Keep us informed of your project rherman.:wave:
    My business Web site - USINUM - www.cooptel.qc.ca/~usinum
    My BLOG at Blogger - http://pacosarea.blogspot.com/

  9. #9
    Join Date
    Jun 2005
    Posts
    55
    Certainly. I have to get back to it. I've been swamped making my rent and bills. Thanks.

    Rob

  10. #10
    Join Date
    Feb 2005
    Posts
    750
    Vitrtual Sculpter 3D is a nice grayscale to DNC program with a free 30 day demo version. Do a search on the net if you want to have something for thirty days anyway. It sems like a very good program, I used it a couple of times but my trial ran out.
    Halfnutz

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  11. #11
    Join Date
    Jun 2005
    Posts
    55
    Yes, I came upon VS3D after I started my program. It is a very good program. I didn't need the cam side of it, however, and I am trying to create algorithms specifically for portraiture taking the hand work out of creating reliefs.

    Rob

  12. #12
    Join Date
    Jul 2005
    Posts
    181
    This sounds interesting. The ability to specify tool diameter and pick distance would be nice. I noticed in your PHP code that you step one way through the image array. This is not good because at the end of one line it will gouge through the part to get to the start of the next line (potentially anyways). It would be better to scan through a line, move to the next line and go through that one in the reverse direction. That way you get no gouging.

    I might code up something like this myself. I've got a C backend VB front end program that I wrote a while back that does some nifty CNC operations plus does some research related things (like creating octrees and visualizing them in OpenGL). I might try to add something like this to it. Or maybe I'll make it a seperate program.

    I hope you don't mind if I try to do what you are doing but in C instead of PHP. A neat thing you might be able to do is make your PHP code accessable over a website so that people can upload their PNG files and get the GCODE output right over the internet. That'd be COOL.

  13. #13
    Join Date
    Feb 2005
    Posts
    303
    I wrote this about a year ago; I can develop it further if anyone thinks it's worth it!
    Attached Files Attached Files

  14. #14
    Join Date
    Jul 2005
    Posts
    181
    Well, after one day here is what I've got. Attached is my try at this grayscale image to GCode thing. ;-)

    The attached is in EXE and source form. It supports a range of input file types. It's configurable and seems to work for me. I'll keep working on it in the coming days but in the meantime maybe someone can try it and see how it works for them?
    Attached Files Attached Files

  15. #15
    Join Date
    Oct 2005
    Posts
    12
    chris radek wrote a somewhat usable image to gcode script in Python that accepts a greyscale .gif file as input and works well with EMC.
    If you haven't already seen it:
    http://timeguy.com/cradek/image-to-gcode

  16. #16
    Join Date
    Aug 2005
    Posts
    276
    have you guys had a look at "IMAGE-dig" it converts .jpegs (or other formats) to a vectorized graph and produces x, y, z co-ordinates. another good program that might give some ideas is "Profiler-6" (see Attached) it has sorce code included, along with a few stipulations on it's use,

    It might give sme ideas a kick
    Attached Files Attached Files

  17. #17
    Join Date
    Sep 2007
    Posts
    1
    Quote Originally Posted by ghyman View Post
    BMP2XYZ program > I wrote this about a year ago; I can develop it further if anyone thinks it's worth it!
    I like this program , only the tooth patteren I can not get close enough to make a close cut . Just can not get how the settings work with large picks , 12" by 15" . When I blow it up the cut lines are to far apart . Any seggesions ?

  18. #18
    Join Date
    Jul 2005
    Posts
    181
    Well, since they didn't post any source code you're probably stuck there... But you could modify one of the open source programs from this thread (I wrote one of them.) My program was a quick VB project but it wouldn't be too hard to make it do interpolation between pixels to get you the smoothness you desire.

  19. #19
    Join Date
    Feb 2005
    Posts
    303
    Quote Originally Posted by Satbeam View Post
    I like this program , only the tooth patteren I can not get close enough to make a close cut . Just can not get how the settings work with large picks , 12" by 15" . When I blow it up the cut lines are to far apart . Any seggesions ?
    Well, my apologies for waiting so long on this... things sort of fell through the cracks on this; it was more of a "I wonder if this would work" project, and I never really put any finishing touches on it...

    I pulled it out this morning for a totally unrelated reason, but did add a few bells and whistles...

    If you change the 'stepover' amount or the 'X width' of the cutter path, it will now give an estimate of the number of lines of code. 'Estimated' because part of the application goes back over the generated code and removes redundant moves... such as eight consecutive 'Y' moves at the same 'X' and 'Z' coordinates.

    See what you think!
    Attached Files Attached Files

  20. #20
    Join Date
    Jan 2006
    Posts
    55
    Seems like a popular thing to do!

    I wrote a trivial one in C a few days ago just to handle the fact that I wanted to use a ball-nose cutter.

    http://randomtechmakings.blogspot.co...converter.html

    Runs on linux, taking an image and converts it to g-code. It's aware of the size of the tool, and cuts to the surface, not into it. So it's able to handle generating a coarse cut, followed by a fine cut.

    And of cause it merge multiple steps along a line into a single command. Doesn't yet recognize curves, or do isocutting.

    It's actually been used to carve things, so it won't make your machine catch fire. Probably. Maybe.

Page 1 of 2 12

Similar Threads

  1. Autocad to gcode
    By JamesMI in forum Autodesk
    Replies: 17
    Last Post: 12-02-2011, 09:54 AM
  2. Is it possible to get a gcode into Rhino
    By MrBean in forum Rhino 3D
    Replies: 11
    Last Post: 04-03-2005, 01:41 PM
  3. gcode to gcode converter
    By july_favre in forum Uncategorised CAM Discussion
    Replies: 4
    Last Post: 05-25-2004, 12:51 AM
  4. Easily trace an image into your CAD
    By Graphcon in forum News Announcements
    Replies: 0
    Last Post: 11-14-2003, 01:30 PM
  5. Gcode verify autocad plugin
    By balsaman in forum Uncategorised CAM Discussion
    Replies: 1
    Last Post: 10-31-2003, 06:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •