Drawing shapes from raster to vectorial

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.

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

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.

I remembered doing something similar but had to do it with python, outside of dynamo (which uses ironpython):
Look at this

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:

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!

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

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

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

1 Like

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

imgTrace.dyn (36.1 KB)

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


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

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

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

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:

Why not as a CSV?


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.

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

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.


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