Create the 3D printing file (Geometry) from colour image

Hi, everyone
Can you help me to create geometry from image in Grasshopper?
I want to get the stl. file from the image.
Something like the following image.

Geometry from pixel information

Thank you.

What do you want to do?
Get the countour of the black part and extrude it?

Yes, I need to extrude it.
I want to extract the black part into geometry 1 and the red part into geometry 2.
The figure below shows the solid structure manufactured by the 3D printing.
Geometry from pixel information-1

Photo Outline - To Curves - Rhino / Rhino for Windows - McNeel Forum

  • extract the outline, patch the curve and extrude it

so far in theory (101.7 KB)


I read that post you told me and it is very good suggestion, but it’s still different from my question.

Hi, Kim
You took the whole image as a quadrilateral mesh of different colors, and it is very smart.
If it is as shown in the figure below, due to sharp corners, it involves the problem of conversion accuracy. Is it more appropriate to replace it with triangular mesh?
Because I need to get STL files for 3D printing.
Image with sharp corner (8.4 KB)

1 Like

Thanks Kim.
Now you just get the image composed with the point sets.

 I want to extract the blue part into geometry 1(the thickness is 2mm) and the yellow part into geometry 2.
 Your last file (imagesampling_reV1) has solved my problem. For the following figure, how do we choose the right quadrilateral to represent the sharp corner.

As shown in the figure, the generated entity structure is composed of many cubes.
Can it be in the form shown in the figure below?

There is another question.
When I set the size of grid cells in square to 0.1 and the number of grid cells in base plane X direction to 500, the program will die.

@HS_Kim @martinborst1 Please check my reply.



You can just take the black portions after Dispatchor Cull Pattern.

It depends on your image resolution and aspect ratio. If you use a fine high-resolution image, then there would be more chances of getting successful results.

Hi, @HS_Kim
If I want to transfer the sharp corner to the geometry, that is, the yellow region in the figure, I have to adjust the grind size of the squar very small.
I finally want to get the geometric length and width of 70x35mm2.

On the basis of this program, can you extrude the yellow part as part 1 and the purple part as part 2, respectively?

Why don’t you try to reverse the extrusion input data?

Anyway, check this as well. (15.9 KB)

1 Like

Thanks, dear @HS_Kim
For this method compared with the “ (101.7 KB)”, the run speed and geometric accuracy of the program are improved.

Hi, dear Kim
When I was using the code, my computer was close to crashing.
Especially when dealing with a complete picture, see the following figure.

Can you optimize this version of the code?

Try not to use a rather high-resolution image. That’ll create a dense and heavy mesh fr Import Image which will need unwanted calculations.

Have a try again with the attached small image…
image-02 (16.0 KB)

Thank you for improving the algorithm again.
I have another question
If we don’t use high-resolution images, will it affect the generation of 3D entities?
Or is it more efficient to process these images with high-resolution and small size?

Hi, dear @HS_Kim
Can we turn these serrated contact lines into smooth curves in the generated structure where the black and white entities are connected?