Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
Can this discussion help you? - mathematica.stackexchange.com/questions/637/… –  Vitaliy Kaurov Apr 13 '12 at 2:30
    
Does the answer here help? mathematica.stackexchange.com/q/1003/5 –  rm -rf Apr 13 '12 at 2:44
    
The dxf standard can be used to describe 2D objects. Therefore, no specific need for Graphics3D. –  Sjoerd C. de Vries Apr 13 '12 at 5:37
3  
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. –  Sjoerd C. de Vries Apr 13 '12 at 5:44
1  
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). –  Yves Klett Apr 13 '12 at 8:17

3 Answers 3

up vote 19 down vote accepted

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[
   "https://upload.wikimedia.org/wikipedia/commons/c/ce/Spinnennetz_\
im_Gegenlicht.jpg"];

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}]);

Graphics[lines]

Mathematica graphics

or with a 3D touch:

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

Mathematica graphics

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

share|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.

share|improve this answer
    
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. –  Yves Klett Apr 16 '12 at 9:18

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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