How to voxelize a .STL file

I’m wanting to break down a . STL file to a stack of voxel images so that I can use ImageJ functions for 3d image analysis. Is there a plugin available?

[Edit]: the suggestion below does not work as stated for loaded STL files as indicated by @iarganda

Hi @kcstauffer,

it should be possible with the 3D Viewer. You can load .STL files into the 3D Viewer via the ►File menu. Then you can still apply transformations to the object and export it to a stack via ►Edit ►Transformation ►Export transformed image. The result will the 3D stack.

Hello @biovoxxel, I don’t think you can do that unless there is an underlying grayscale image. I just tried it out and got an error:

image

Hi @iarganda,

Autsch :confounded:
Sorry for the incorrect indication. You are right. I obviously had the input stack open ando forgot that the STL file actually only comprises the surface and does not have the intensity info available.
So just forget about my earlier suggestion.

1 Like

Hi all,

We added voxelization to imagej-ops a bit ago: http://javadoc.scijava.org/ImageJ/index.html?net/imagej/ops/geom/geom3d/DefaultVoxelization3D.html

Cheers,
Kyle

1 Like

I don’t know much about coding. Do you have a compressed .jar file so that I can just drop it into the plugins folder and have it work?

Almost! Or rather: there is almost a working ImageJ update site.

We added a page about voxelization to the ImageJ wiki awhile ago. However, those instructions are now outdated. The “ThreeDViewer” is now known as SciView. Much time and effort is being expended by @kephale and @skalarproduktraum and myself to get it to a usable state. One of its features is voxelization of meshes.

We are in the middle of a hackathon this week madly working on this stuff. So please stay tuned; hopefully we will have something for you to try soon.

3 Likes

Looking forward to it. Thanks!

Do we have any update from the December Hackathon? Is the a stable combination of plugins that can Voxelize an .stl today?

Thanks

Not stable. But experimental, yes: you can enable the SciView update site to give it a try as described here (that documentation still says “ThreeDViewer” but the instructions are probably OK otherwise? @kephale?)

Note that the SciView update site is intentionally not on the built-in list of update sites yet, because it is not yet stable enough. But you can use the “Add update site” button to add it manually.

There will be another hackathon in late April specifically dedicated to SciView—the development continues!

1 Like

Hey all,

Actually, to help tease apart graphics and mesh processing dependencies I added a STL voxelization script to FunImageJ.

Just enable the FunImageJ update site (it is in the standard update site list), then access the command via the menu at: Plugins>FunImageJ>Mesh>voxelize mesh. It asks for a STL file and voxel dimensions as input.

Note that voxelization is not a trivial problem, and if you get an unexpected result, then please contact me and I will look into it. There are a couple of folks who are joining me to dive a bit further into some fancier voxelization algorithms in the near future (coinciding with the SciView hackathon).

Cheers,
Kyle

5 Likes

Dear Kyle,

I tried to load a simple stl of 12MB, no luck. tried other files, the same error, which I’m posting below. Any help welcome:

[ERROR] null
java.util.NoSuchElementException, compiling:(NO_SOURCE_FILE:0:0)
	at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3657)
	at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3651)
	at clojure.lang.Compiler$DefExpr.eval(Compiler.java:451)
	at clojure.lang.Compiler.eval(Compiler.java:6932)
	at clojure.lang.Compiler.eval(Compiler.java:6890)
	at org.scijava.plugins.scripting.clojure.ClojureScriptEngine.eval(ClojureScriptEngine.java:88)
	at org.scijava.plugins.scripting.clojure.ClojureScriptEngine.eval(ClojureScriptEngine.java:63)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException
	at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:713)
	at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:734)
	at net.imagej.ops.geom.geom3d.DefaultVoxelization3D.calculate(DefaultVoxelization3D.java:90)
	at net.imagej.ops.geom.geom3d.DefaultVoxelization3D.calculate(DefaultVoxelization3D.java:65)
	at net.imagej.ops.special.function.UnaryFunctionOp.run(UnaryFunctionOp.java:74)
	at net.imagej.ops.special.function.AbstractUnaryFunctionOp.run(AbstractUnaryFunctionOp.java:58)
	at org.scijava.command.CommandModule.run(CommandModule.java:199)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:938)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:134)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93)
	at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
	at fun.imagej.ops$run_op.invokeStatic(ops.clj:129)
	at fun.imagej.ops$run_op.invoke(ops.clj:125)
	at clojure.lang.AFn.applyToHelper(AFn.java:156)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3652)
	... 15 more
[ERROR] null

Can you post one of the stl’s as an example? I just tried and it still seems to work for me.

Hi, I would love to try the stl to voxel converter but I’ve been trying hi and lo to find the plugin and instructions on how to install it.

Sorry to be such a noob but really I can’t google myself out of this with +35 years of programming experience … this must be simple but no can do.

The easiest way at the moment is:

  1. Install the SciView update site. It is available in the list of update sites and should be a checkbox in your Fiji updater.
  2. Open SciView
  3. Open your STL in SciView
  4. In the SciView menu: Process > Mesh to Image

Alternatively, for programmatic access you can explore imagej-ops, and you will find it listed in the geom namespace as voxelization. You will need to use imagej-mesh to open the STL.

1 Like


I use SciView and mesh to image.
but my results have no mesh on the edges. i.e. my edges are not close.


Is that fixable by imagej or other processing?

Dear Khyle,

I would like to come back to the post by danivision regarding FunImageJ, because I have exactly the same error messages in my log, when I try to upload any stl files. Alternatively, there is no error message and no output. Moreover, I’m not able to start SciView at all, the starting window appears and ImageJ crashes. May it be that I there are any other plugins in use, so they have to be installed? Any special system requirments? Any help is very appreciate.

Best,
Anna

Hi Anna,

I’m looking into this. We are pushing to make a new SciView release soon, so I’m hoping to ask that you try that release in hopes that it resolves this issue. Please feel free to poke me about that, but a new SciView release is one of the top priorities right now.

Cheers,
Kyle

Thanks for pointing out this bug. I have opened a GitHub issue to track this: https://github.com/imagej/imagej-ops/issues/603