I am trying to convert some stl files to 3d images in MMA 11.3. I came across this post that contained some code making use of parallelization to speed up the process, as follows:

voxelify[region_?RegionQ, res_?NumericQ] := 

Module[{f, bounds, boxsize, voxsize, data, d2},
  f = RegionDistance[region];
  bounds = RegionBounds[region]; 
  boxsize = -Subtract @@ # & /@ bounds;
  voxsize = Max[boxsize]/res; 
  data = ParallelArray[f[{##}] &, Round[boxsize/voxsize], bounds]; 
  d2 = HeavisideTheta[data - voxsize]; 
  2 - ReplaceAll[WatershedComponents[Image3D[1 - d2]], {0 -> 2}]

Very nice. Unfortunately it doesnt work, but produces an error message:

enter image description here

It then proceeds with a very slow sequential evaluation taking several minutes, rather than seconds.

Thinking that perhaps this was due to changes in the functionality of ParallelArray, I reinstalled MMA10.0, then MMA10.3, but they both produced the same error. I have no idea how the OP got the code to work originally.

Is anyone able to suggest a fix for this code? Or an alternative approach that is equally efficient?

  • 1
    $\begingroup$ Have you seen RegionImage? $\endgroup$ – Chip Hurst Apr 2 at 12:03
  • $\begingroup$ Yes, but I am not clear how that helps.... $\endgroup$ – Jonathan Kinlay Apr 2 at 13:05

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.