How to generate extruded 3D model from images in OpenSCAD

Recently, to do a little bit of 3D modeling, I wanted to try my hand at making a modular back cover for my iPhone. Yes, there’s too many 3D printable models of iPhone covers, but sometimes, we reinvent wheels not to have more wheels, but to have more inventors. To do something a bit more organic, my concept was to have a pattern of leaf veins for my iPhone backcover, Graftleaf.

However, instead of drawing a leaf pattern myself, I generated the pattern from an image using free tools. That’s what the rest of this tutorial will help you do, and what I learned.

First, I had to go find a creative commons image of some leaf veins. I need something that was CC-BY, which allowed derivative works. I also needed the image to be sharp (damn you, tilt-shift) with high contrast. I used flickr’s advanced search, so you can look for CC images.

There were a good number of results, but I picked this one by Steve Jurvetson, which fulfilled my criteria above.

Next, I fired up GIMP, an open source alternative to Photoshop. After you open up GIMP, then open up the leaf vein picture above through File -> Open.

Screen Shot 2013-11-09 at 6.34.06 PM

Now we want to convert it to grayscale. Image -> Mode -> Grayscale.

Screen Shot 2013-11-09 at 6.34.50 PM

However, the colors are inverted. We want the veins to be black. Colors -> Level.

Screen Shot 2013-11-09 at 6.35.41 PM

Move switch the positions of the black and white arrows in “Output Levels”

Screen Shot 2013-11-09 at 6.36.28 PM

Screen Shot 2013-11-09 at 6.37.36 PM

Now, we want to make the veins a solid black and white. Choose Colors -> Threshold. Adjust it until it the veins are thick, but there aren’t too many spots in the cells between the veins.

Screen Shot 2013-11-09 at 6.38.03 PM

Screen Shot 2013-11-09 at 6.39.27 PM

Lastly, we want to crop the image to make the details more visible, as well as reducing the complexity of the image, so the PNG to DXF conversion won’t take a long time.

Screen Shot 2013-11-09 at 6.44.45 PM

Screen Shot 2013-11-09 at 6.44.57 PM

Now that our image is edge detected, and we can now save it to a file as a PNG. Now, we’ll use an open source tool for vector drawings, called Inkscape, to convert the PNG to DXF.

This is where OpenSCAD gets a little finicky. It can’t read all types of DXF files, so we need to install an Inkscape extension that allows us to save DXF files in a format OpenSCAD can read. Go download the extension. To install it in Inkscape, copy the *.py and *.inx files (in the zip file of the extension) to your Inkscape extensions folder. Where the extensions folder is located depends on what system you’re using.

  • Linux: ~/.config/inkscape/extensions/
  • Mac OS X: /Applications/
  • Windows: C:\Program Files\Inkscape\share\extensions\

(If you’re all-pro, you can use git to clone the extension into the inkscape extension folder.)

Once you have that installed, open up Inkscape and load up the leaf PNG we just saved. When it asks you if you want to link or embed, choose embed.

Screen Shot 2013-11-09 at 7.19.03 PM

Next, we want to trace the bitmap we have as a path. First select the bitmap by clicking on it. Then Path -> Trace Bitmap. I just used the default options, but you can play around with things then click update to see what it would look like.

Screen Shot 2013-11-09 at 7.19.47 PM

Screen Shot 2013-11-09 at 7.26.38 PM

Now you have two objects on the canvas. One is a vector path of the leaf veins, overlaid on top of the bitmap of the leaf veins. Move the vector path out of the way by dragging and dropping it. Then select the bitmap and delete it. Then move the vector path back.

Screen Shot 2013-11-09 at 7.28.26 PM

Now, we can save it to DWF using the extension we installed earlier. File -> Save As. Make sure you select “OpenSCAD DXF Output (*.DXF)” as the file type to save as.

Screen Shot 2013-11-10 at 10.17.09 AM

We finally have our DXF file that we can use in OpenSCAD, as you can see all the assets.

Now, we can use it in our OpenSCAD! We can write the OpenSCAD snippet:

linear_extrude(height = 4)

Screen Shot 2013-11-10 at 10.45.43 AM

In making Graftleaf, I actually did the additional step of compiling with CGAL (F6 in OpenSCAD), and then exporting the result to STL. Then using the STL in the final model, for faster renders.

Screen Shot 2013-11-10 at 10.47.36 AM


If you found this more advanced OpenSCAD tutorial helpful, let me know! I’ll write more. Have a great week!

Tagged with: ,
Posted in openscad, tutorial
21 comments on “How to generate extruded 3D model from images in OpenSCAD
  1. Len says:

    I enjoyed reading this tutorial, so count this as a vote for more posts like this! Thanks Wil.

  2. mohammadthalif says:

    Thanks your very much for this well written and easy to following tutorial, Hope to see more,

  3. avl says:

    I am having trouble with the installation. I can’t find the extensions folder for inkscape. And what commands do you use to install it in the extensions folder? Thank you!

    • iamwil says:

      I’ve updated the post to show different locations on different systems.

      These files are located in different directories on different platforms:

      Linux: ~/.config/inkscape/extensions/
      Mac OS X: /Applications/
      Windows: C:\Program Files\Inkscape\share\extensions\

      There’s no command. All you have to do is copy the *.py and *.inx file into the inkscape extension folder. And then restart Inkscape.

  4. […] And that’s it! That’s really all you need to know to get started and get dangerous in OpenSCAD. If you would like to see how other chess pieces were written, check out king’s gambit, my first 3D printed project using OpenSCAD. If you’d like to learn more, check out a previous more advance tutorial on how to generate patterns from images with OpenSCAD. […]

  5. […] I showed you how to extrude images in OpenSCAD, and a beginner’s guide to OpenSCAD. This time it’s a more advanced method on how to […]

  6. Midwire says:

    I too find these kinds of OpenSCAD posts enjoyable and informative. Thanks Wil.

  7. James says:

    Awesome and easy to follow.
    Here is what I was able to design with it:

  8. raulmerlin says:

    Great tutorial!! Thanks!!!!

  9. Pedro says:

    i want to know the last librery you use “../lib/graftconcepts.scad” where can i find it???

  10. I get an error when trying to export the file using the dwf extension. The dwf file will then load, but when imported into openscad, I get an error saying ‘no top level geomtry to render’. I definetly put the extension files in the right folder. What do you think is wrong?

  11. fqantonio says:

    Well the question is simple: the path must be complete in order to openscad find the file. Even so, openscad can’t open it.
    Best, thank you for your tutorial.

  12. ufomorace says:

    Oscad now supports png’s, i just tried a bw 1024 one it works just by drag png into oscad. color png didnt work.

  13. […] InkScape? Inkscape seems to be a very powerful way of turning images, logos, and patterns into scalable vector graphic images that you can import into Blender or other modeling software. I’ve seen many people having success with it on the Internet. […]

  14. j.o.young says:

    Exactly what I needed to print the custom didgeridoo mouthpiece of my dreams. Thanks for sharing. BTW: (maybe in the Windows world only) the bitmap is on top after tracing.

  15. norfX says:

    Thanks for your precious help!

  16. petrgasparik says:

    Great and on the spot. No lines wasted.
    Thank you!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Work on 3D printed projects together.
Host your 3D printed projects on Cubehero, and get 3D Model previews and git based version control.

%d bloggers like this: