Drawing shapes from raster to vectorial

#1

Hi all,
How can i draw a polyline or a spline based on a raster image like the one attached? Because i have several images and i’m trying to find a way to make this tracing automated.
Thank you.

EDIT: all the images i’ve to treat have this color red lines and the background transparent.

0 Likes

#2

please see this FAQ - posting some things that you have tried, or searched for and did not work would help: How to get help on the Dynamo forums

0 Likes

#3

Thank you for your reply.
I haven’t tried anything yet, because i usually draw my outlines in AutoCAD and then i import them in Revit.
I asked on purpose because I’m not practical to dynamo and maybe there is a simple command to do my task.
If my request is not clear, please let me know and i’ll try to explain it better.

0 Likes

#4

I remembered doing something similar but had to do it with python, outside of dynamo (which uses ironpython):
Look at this
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_contours/py_table_of_contents_contours/py_table_of_contents_contours.html#table-of-content-contours

0 Likes

#5

Thank you @GregX I was looking for something similar, like the function ConvexHull of OpenCV. It’s ok if i have to do something in Python because the images i’ve to analize come from an automated custom object detection model written in pyhton.
Maybe to make it more flexible for Dynamo i was thinking to use a text file with all the outlines’ coordinates so, instead of tracing a raster object, Dynamo has to Draw only polylines; the only issue could be passign these coordinates in the right order, like all clockwise, and being careful to draw separated polylines for each different object.
I hope i’ve written everything correctly :slight_smile:

0 Likes

#6

I can’t remember well but when I ran my python script with opencv it exported a txt file with a list of polylines with its points coordinates, so you should just be able to read that in dynamo and do what you have to do!

0 Likes

#7

It sounds more practical doing something like this!
Thank you again, i’ll try to modify my code on python!

0 Likes

#8

If you manage to make It work could you post your solution in order to help other members of the forum that may stumble upon this post? Thanks!

1 Like

#9

For sure i’ll post the Dynamo’s implementation if i ever find a solution :smile:

1 Like

#10

@Francesco_Cavazzini Managed this on a small part of your image.
img0

imgTrace.dyn (36.1 KB)

Note: To group contiguous points a variation of the Group Curves definition is used

3 Likes

#11

Thank you very much!!! I’m trying it right now!
How long did it take to complete the process?

0 Likes

#12

Took about a minute for this small image.
Could speed the process by reducing accuracy/number of points (by increasing the value on the slider)
With the complete image, this approach may not be very efficient.

1 Like

#13

I see… Unfortunately i have to treat large images in a large number :sweat_smile:

0 Likes

#14

I’m trying to change my code in python and extract, instead of the raster images, the coordinates i’ve used to draw the outlines, to import them in Dynamo and use something like Point.ByCoordinates (x,y) to draw my polygons.
How should format my txt file with the coordinates to import in Dynamo and how i can cycle through the entire list of numbers to set them as coordinate x1=…; y1=…; x2=… ; y2=… ??
Thank you :slight_smile:

0 Likes

#15

Why not as a CSV?

0,0
1,1
2,2

Dynamo can read the csv as numbers instead of as text, saving you a bit of hassle converting and such. Then it will just be transposing the list into X and Y values and running from there.

0 Likes

#16

Oh thank you, that’s a great suggestion! I’m slowly learning how to use Dynamo :slight_smile:

0 Likes

#17

Do the primer in its entirety, even if things feel like you won’t need them. Will save you a lot of headaches as the exercises are intended to teach the concepts in use not for the intended results.

3 Likes

#18

That’s my results by now… I still have to figure out how to draw multiple polygons.

0 Likes