5

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["https://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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
PCK
  • 51
  • 1
  • 3
    Is there no format in common between these applications? – Mr.Wizard May 21 '15 at 16:40
  • 3
    Why don't you also include an example profile where your code doesn't work? – Mr.Wizard May 21 '15 at 16:46
  • So that's the thing, the code I posted doesn't really work. It gets outlines from the shape, but they don't match perfectly. Also, because the profile is actually a really thin 2d line, there are two sets of lines generated, one for the inner surface and one for the outer surface. I think I know how to solve both of those problems, but I was hoping someone in the community might have a better solution, because I really don't have a clue what I'm doing. – PCK May 21 '15 at 19:03
  • To solve the problem of 2 sets of lines, I plan on making a function that goes through the list and averages any 2 vertices that are really close to each other. – PCK May 21 '15 at 19:06
  • 1
    Which version of Mathematica are you using? In 10.1 I get this: http://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? – Mr.Wizard May 21 '15 at 19:08
  • 1
    Thanks for asking twice. I googled harder and discovered that dxf files are reasonably compatible with mathematica. – PCK May 21 '15 at 19:32

1 Answers1

5

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]
LCarvalho
  • 9,233
  • 4
  • 40
  • 96