0
$\begingroup$

I'm trying to convert a 2d image to a 3d object that can be digested by 3d slicing software, specifically the algorithm contained here http://archive.bridgesmathart.org/2013/bridges2013-311.pdf

I had to convert the input/output of the routine to the below, however my cloud file just contains the wolfram comment 'created by wolfram' and no actual STL file.

SetDirectory[$UserDocumentsDirectory];
img=ColorConvert[Import["bone.png"],"Grayscale"]      (* import the image as values in range 0..1 *)
height = 2.0;   (* height of cylinder.  Units are set in the 3D printer *)
alpha = 0.1;   (* max relief depth, as fraction of height, typically around 0.1, or -0.1 for inverting *)
{n,m} = ImageDimensions[img];
rMid=n * height/(2 Pi m) ;     (* scale so pixels are square at mid-depth*)
r=Map[rMid-alpha height (#-0.5)&,ImageData[img],{2}];   (* convert to table of radii *)
xyz=Table[{r[[j,i]]Sin[2 Pi i/n],r[[j,i]]Cos[2 Pi i/n],(1-j/m) height},{i,1,n},{j,1,m}];   (* convert to Cartesian *)
(* the cylinder consists of three parts: the curved surface with the image and two circular caps: *)
surface=Table[{xyz[[i,j]],xyz[[Mod[i+1,n,1],j]],xyz[[Mod[i+1,n,1],j+1]],xyz[[i,j+1]]},{i,1,n},{j,1,m-1}];
bottom=Table[{{0,0,0},xyz[[i,m]],xyz[[Mod[i+1,n,1],m]]},{i,1,n}];
top=Table[{{0,0,(1-1/m)height},xyz[[Mod[i+1,n,1],1]],xyz[[i,1]]},{i,1,n}];
g=Graphics3D[{EdgeForm[],Map[Polygon,Join[surface,top,bottom]]}] ;
CloudExport[g,"stl","export.stl"];
$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Feb 9 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.