I'm trying to convert a 2D image into a 3D printable sculpture using just code. First I would like to know if it can be done with just a script? I already know Python and C and would be great of course if I could use one of these to do what I want.
Here are two links for you to see what I mean by saying "Turn any 2D image into 3D printable sculpture" (but these are using software):
https://www.youtube.com/watch?v=ngZwibfaysc
https://www.youtube.com/watch?v=-fe2zxcKSic
To be more specific I want to insert an image and just wait to get the result which will be a 3D sculpture.
was curious a bit so I encoded a small example of illumination surface encoding
height = (color_intensity)*scale
This is input image I tested with (first nice Oil painting in Google search):
This is the result (point cloud 3D preview)
On the left is animated gif so reload/refresh page to see the animation if it is already stopped or download the gif and open in something more decend then brownser for gif preview... On the right is colored point cloud preview (static image)
This is the C++ code for computing this:
Here OpenGL preview code (C++):
Matrices are set like this:
[notes]
I am using own picture class so here some members:
xs,ys
size of image in pixelsp[y][x].dd
is pixel at (x,y) position as 32 bit integer typep[y][x].db[4]
is pixel access by color bands (r,g,b,a)Also I am using custom OpenGl
scr
and Texture Clases:xs,ys
size of buffer in pixelsTexture::txr
is 32bit pixel pointer (image is allocated as linear 1D array)The only thing left to do is:
There are other ways to encode illumination into surface:
you can do something like Fresnel lens surface
That need much less volume/material
First half of animation is normal height encoding then it is switched to Fresnel surface encoding/packing for comparison
encode illumination not as height map but as roughness map instead
This will be visible also from angles and can be relatively thin so need very little material for this (much less then previous bullet)
Real height map (real 3D mesh representation)
It is very tricky you need to normalize colors, shadows and illumination artifacts so only normal shading is left (as the surface is from single material,color,shininess,roughness ...) and only then extract the height map. For that you need many things like segmentation, adaptive tresholding, filtering and much more ... At last add the empty inside and add support walls so the mesh holds together while/after printing.