I'm currently trying to take a 2d profile generated in SolidWorks and use mathematica to analyze it. I need to pull lines that represent the boundaries of the shape from an image of the shape. Image can be found here. My current approach is to save the profile as a jpg/png in solidworks, then importing that image to mathematica. I've tried a lot of things, with varying degrees of success:

img = Binarize[
edges = ImageLines[EdgeDetect[img], 
  Method -> {"Hough", 
    "Segmented" -> 
edgeimg = Graphics[{Thick, Orange, Line /@ edges}]
MorphologicalTransform[img, "Commonest"]

Has gotten me the closest, but it's far from perfect. Has anyone tried anything similar and had any success? Also, I started learning mathematica yesterday, which is also the first time I've tried image processing, so some explanation of the code would be really nice if it's really convoluted.

The end goal is that I have different lines that fully describe the profile of my object that can be individually selected.

BONUS: I have literally no clue how to incorporate curves into something like this, but that's another goal.

  • 3
    $\begingroup$ Is there no format in common between these applications? $\endgroup$
    – Mr.Wizard
    May 21, 2015 at 16:40
  • $\begingroup$ Related: (13918), (18167) $\endgroup$
    – Mr.Wizard
    May 21, 2015 at 16:41
  • 3
    $\begingroup$ Why don't you also include an example profile where your code doesn't work? $\endgroup$
    – Mr.Wizard
    May 21, 2015 at 16:46
  • 1
    $\begingroup$ Which version of Mathematica are you using? In 10.1 I get this: i.stack.imgur.com/LHyj4.png -- which looks pretty good to me. Before attempting to improve this though I ask again: is there no format in common that you could export in? $\endgroup$
    – Mr.Wizard
    May 21, 2015 at 19:08
  • 1
    $\begingroup$ Thanks for asking twice. I googled harder and discovered that dxf files are reasonably compatible with mathematica. $\endgroup$
    – PCK
    May 21, 2015 at 19:32

1 Answer 1


You need to create the profile in SolidWorks drawing environment and save it as DXF file.

Import it through the import function...

im=Import["C:\\Users\\Leandro\\Desktop\\Arco.dxf","Graphics3D"] InputForm[%]

And export it as a jpg or png file...

Export["image.png",im, ImageResolution -> 360]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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