Process Images to Split geometry for Color changes

Hi, i want to split geometry when the color of an image changes.
Is that possible? And what would your approach be?
Can i read from file (the image) and get the border of black versus another color and make a line at that point?
mandala.dyn (19.7 KB)
PNG mandala2

Maybe Adobe Illustrator>export>dwg?
Thnx @callbowen

i might be onto something here:
lets do a pixel count, it says 1335(w)x758(h)
now create a rectangle in the above dimensions, thicken
split geometry by the number of pixels giving you 1011930 little squares
color them or change it by giving it materials (get the color of the pixels)
dont forget to check if the node reads them top/down or left/right
get rid of the black ones (hide we need them later on)
go for some coffee and come back later :slight_smile:
smooth out some edges, scale it

i could do with some more ideas

Tsplines perhaps?

good idea,
for the smoothing out part that would be super
the more basic idee of getting from picture to a revit family is what i’m after
imagine, it would work for any picture if no angle is involved

@Vikram_Subbaiah the master himself has done a few image data extractions during his time on the forum. Perhaps he can advise? (I was toying around with this today as well and got some of the extraction working using your workflow @Marcel_Rijsmus :yum:)

Or perhaps this workflow could be massaged… by converting your image to black and white?

1 Like

[quote=“Ewan_Opie, post:6, topic:35836, full:true”]
(I was toying around with this today as well and got some of the extraction working using your workflow @Marcel_Rijsmus :yum:)

can you share the .dyn?

would spltting up the surface be more efficient than repeating a cuboid (pixel)?

I would think that unique pixel creation in the first instance would be much faster than a recursive splitting of any geometry, at least that was the workflow I was using.

I was also testing the of sorting points based on their colors to enable smaller surfaces to be created as zones, (kind of like the stained glass itself) with various success, though I think there is room for huge improvement.

Some kind of implementation on Canny Edge detection or Hough Line Transform would be really cool though. Will ponder that a bit more. :thinking:

Will post tomorrow what Ive got when back at the PC :computer:


If we’re talking about pixelated geometry - it’s easy.
Read the image as a desired amount of pixels. Build geometry with the same amount of square surfaces.
Group the surfaces by R G B values and then… do whatever you want to do with that…
If the goal is vectors… I’d go for a vectorizing software (Illustrator or something else or even an online vectorizing service).
I saw a post some years ago about a Python algorithm that recognises shapes in a raster image. But it recognizes rectangles, circles and ellipses only if I remember correctly.

Theoretically in Dynamo we can use the raster approach and then use these squares (surfaces or just linear polygones) and then draw lines throw their boundaries. Like let’s say:
Get all black pixels as surfaces. Join them into one polysurface. Get the boundaries. of that polysurface and simplify them so they’re not jagged. But I can imagine this being too heavy computationally for any practical use.

Just my 2 cents of course, there are people on this forum that have proven they are able of doing the impossible.

1 Like

I’ve tried my own approach as proof of concept, it work but is very heavy on memory to the point where all 16Gb is used and it starts spooling. So this is not a working solution.
geo_from_image.dyn (24.6 KB)

Will try a divided suface now.
Edit: divided surfaces can only handle up to 200x200 panels. mesh maybe?

So here is a working pixel prototype, with a very small image your proof of concept is good.
(Note that for larger images run-time has been quite slow as expected)
This method requires pre-processing of images to create a skeleton and color map to keep edges crisp.
I used for this.

The material creation part requires refinement, as I was creating materials each run, not reusing existing ones or mapping my colors to existing materials.

Test images for download:

Dynamo v2.0 - Image to Pixel Surface.dyn (85.0 KB)


A better approach could be to pointcloud the image? (jpg - csv - las - rcs)
Dynamo v2.0 - Image to CSV for Pointcloud.dyn (69.4 KB)


Thanx @Ewan_Opie :+1:
I can’t download the test images but that’s a forum issue i think. can you Zip them and upload again.
i have to study this.

@Marcel_Rijsmus Improved quality of the below approach takes very long.

img-gtry.dyn (12.8 KB)

imgDim = Image.Dimensions(img);
pxlWdt = imgDim["width"]/15;
pxlHgt = imgDim["height"]/15;

pntGrd = List.Reverse(Point.ByCoordinates

pxlClr = Image.Pixels(img,pxlWdt,pxlHgt);
pxlBrg = Color.Brightness(pxlClr);

blkPnt = List.Flatten(List.FilterByBoolMask

blkSrf = Solid.ByUnion(Rectangle.ByWidthLength(1,1)

Not sure it’s efficient, but now I had to respond :slight_smile:


Thanx @Vikram_Subbaiah
Can i perhaps split up the image by color make anything red-like into red, and make a surface out of that?
It just might take 4 goes for every basic color red,green,blue and black but it might also be quicker.

1 Like

Why not just black? (Image quality perhaps?)

i would like to be able to have a set of different materials for every type of stained glass to make it look good. thnx @JacobSmall

Well, I may be mistaken, but doesn’t stained glass there is a black border between each color. If so:

Split the original surface at the black pixels.
Use the resulting surfaces as hosts for the new colors, getting the color value at the center of each new surface (you may need to rebuild by Surface.PerimeterCurves, polycurve.ByJoinedCurves, Surface.ByPatch as the UV maintains the original extents).

1 Like

by type of glass i meant the color of it, so red glass, green glass and so on. The black stuff in between is metal holding it all together.

Yep - find the surface for each piece of glass as I noted, the point at parameter 0.5,0.5 for each surface of glass, find the UV parameter of that point on the original surface, find the corresponding pixel color at that point by mapping the UV to your image resolution. The resulting color is your glass type for each glass surface. Thicken your glass surfaces into full geometries (or leave them flat if you’re thinking sketch-up style is an ok modeling method for your needs), and apply the color/glass type accordingly. No need to do the complex and computationally expensive ‘edge finding’ for each color (unless you’re missing a black boarder somewhere).

i get the point @JacobSmall i need some time to imagine the dyn