I have an image I would like to make into a .dxf and to do this I need a Graphics3D object. Is there anyway I can do this?

Can mathematica somehow vectorize a 2D image? I tried saving the image as a PDF then Export[path.dxf,Import[path.pdf]] after saving EdgeDetect[Image] as a PDF but AutoCad said it was a bad DXF and did not accept it.

Any solutions?

Edit: Clarification: I have a 2d image that i want to put into the .dxf format which I believe is 3d. In order to do that Mathematica wants a Export[path.dxf,3DGraphics object]. It's a 2d image though. This is for importation into AutoCAD. It says malformed shape when i do Export[path.dxf,Image] since I assume Image is 2DGraphics object

  • $\begingroup$ Can this discussion help you? - mathematica.stackexchange.com/questions/637/… $\endgroup$ – Vitaliy Kaurov Apr 13 '12 at 2:30
  • $\begingroup$ Does the answer here help? mathematica.stackexchange.com/q/1003/5 $\endgroup$ – rm -rf Apr 13 '12 at 2:44
  • $\begingroup$ The dxf standard can be used to describe 2D objects. Therefore, no specific need for Graphics3D. $\endgroup$ – Sjoerd C. de Vries Apr 13 '12 at 5:37
  • 3
    $\begingroup$ PDFs don't necessarily contain vector graphics. The standard also includes bitmaps. So if you Export an image as PDF you won't automagically create vector graphics. $\endgroup$ – Sjoerd C. de Vries Apr 13 '12 at 5:44
  • 1
    $\begingroup$ Mathematica DXF does export to some kind of 3D non-AutoCAD spec. Many programs accept that (e.g. Rhino 3D) but others do not. If you want to export 2D DXF let me know. I may have some awful legacy code that does work for some programs (not at hand though). $\endgroup$ – Yves Klett Apr 13 '12 at 8:17

This maybe helpful if you want to convert image structure into 2D/3D line primitives, MorphologicalGraph does some astonishing things out of the box:

img = Import[

Mathematica graphics

g = MorphologicalGraph[img // MorphologicalBinarize, 
   VertexCoordinates -> Automatic, EdgeWeight -> Automatic];

edges = EdgeList[g];

extracting the actual connections can be done like this (although more streamlined solutions would be welcome):

vertices = 
  Thread[Rule[VertexList[g], PropertyValue[g, VertexCoordinates]]];

lines = ((edges /. vertices) /. 
    UndirectedEdge[a_, b_] :> Line[{a, b}]);


Mathematica graphics

or with a 3D touch:

 Tube[#] & /@ (lines /. {x_?NumericQ, y_?NumericQ} :> {x, 0, y})]

Mathematica graphics

After that, you can choose your preferred 2D/3D vector format for Export.

| improve this answer | |

If you don't have any specific needs to do it with mathematica... why don't you use autocad raster design. It makes the most of raster images, maps, aerial photos, satellite imagery, and digital elevation models. With powerful raster editing and raster-to-vector conversion tools, AutoCAD Raster Design software helps you to easily clean up, edit, enhance, and maintain scanned drawings and plans in a familiar AutoCAD software environment. There are also many free software does that for you even online.

| improve this answer | |

If I understand your question correctly, you can include your 2D image in a 3D scene by texturing it on a square (or rectangle):

img = ExampleData[{"TestImage", "Lena"}];
g = Graphics3D[{Texture[img], 
  Polygon[{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, 
   VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]
Export["toto.dxf", g]

This does not give error messages, but I cannot tell you for sure that AutoCAD will open the resulting file.

| improve this answer | |
  • $\begingroup$ This does not seem to work with 8.04 on Win 7 (nor do I think with other versions so far). All I get is a polygon net with two triangular faces. If you look into the file, there is no trace of any texture. $\endgroup$ – Yves Klett Apr 16 '12 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.