4
$\begingroup$

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[
  Import["http://i.stack.imgur.com/BNRjk.png"]]
edges = ImageLines[EdgeDetect[img], 
  Method -> {"Hough", 
    "Segmented" -> 
     True}](*EDGES HOLDS LINES WHICH CORRESPOND TO EACH EDGE OF THE \
SHAPE*)
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.

$\endgroup$
  • 3
    $\begingroup$ Is there no format in common between these applications? $\endgroup$ – Mr.Wizard May 21 '15 at 16:40
  • $\begingroup$ Related: (13918), (18167) $\endgroup$ – Mr.Wizard May 21 '15 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 '15 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 '15 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 '15 at 19:32
4
$\begingroup$

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]
$\endgroup$

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.