Error with converting mesh to image

I have been trying to use SciView to convert an STL or OBJ file into an image stack using the thread here: Converting .STL file into stack of images. Based on the information shared there, I started following the instructions on the ImageJ Voxelization webpage: https://imagej.net/Voxelization.

I can get the 3D model imported into Fiji through SciView but receive the following error in the console:

[ERROR] No SciJava display available. Use getOrCreateActiveSciView() to automatically create a display if one does not exist.

When I select “Mesh To Image”, I receive the following error message in the console and then no image stack is created:

[ERROR] Module threw exception
java.lang.IndexOutOfBoundsException
	at java.nio.Buffer.checkIndex(Buffer.java:540)
	at java.nio.DirectFloatBufferU.get(DirectFloatBufferU.java:253)
	at net.imagej.mesh.nio.BufferMesh$Vertices.xf(BufferMesh.java:135)
	at net.imagej.mesh.Vertices.x(Vertices.java:134)
	at net.imagej.mesh.Vertex.x(Vertex.java:95)
	at net.imagej.mesh.Vertex.localize(Vertex.java:144)
	at net.imglib2.RealPoint.<init>(RealPoint.java:108)
	at net.imagej.ops.geom.geom3d.DefaultVoxelization3D.calculate(DefaultVoxelization3D.java:85)
	at net.imagej.ops.geom.geom3d.DefaultVoxelization3D.calculate(DefaultVoxelization3D.java:62)
	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:950)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:157)
	at net.imagej.ops.geom.GeomNamespace.voxelization(GeomNamespace.java:284)
	at sc.iview.commands.process.MeshToImage.run(MeshToImage.java:83)
	at org.scijava.command.CommandModule.run(CommandModule.java:199)
	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.lambda$wrap$2(DefaultThreadService.java:228)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

I am running Fiji / ImageJ version 2.0.0-rc-71/1.52p, build: ea9a94b5e9.

Could anyone offer some recommendations on how to troubleshoot this, or alternative procedures to convert an STL to an image stack?

Thanks for your time!

1 Like

Hi @MorphoFun

Could you link your STL so I can double check what is happening?

Cheers,
Kyle

1 Like

@kephale, i have the Same Problem, i want to convert my STL file into stack of images or voxelize it, at the difference that when clicking on Mesh to image, the result is something that i can Not explain. Please could i link you my STL file too? I am stuck for weeks with this issue. I am using Windows 10 home edition
Thanks in advance for your time

1 Like

Yes, please link it. We’d like to clear up these issues for an upcoming release anyway, so this is good timing!

Thanks a lot for your time

pipebuble2.zip (2.9 KB)

Hi @kephale,

Thanks so much for your response!

Here is a link to the 3D models that I have been toying around with: https://drive.google.com/drive/folders/1AhOsB19yTfXEqRE1uLCLIBVnyMKoh71J?usp=sharing. I made a sphere in MeshMixer that had a diameter of 25 mm, so I could test out the procedures before moving onto my more complex geometries.

I think I partially figured out my problem, though. I was following the directions from the ImageJ voxelization webpage that said that I could use OBJs, and the errors reported at the beginning of my post was for the OBJ. When I converted the OBJ to an STL, I was able to generate the image stack (yay!). Is this something that other users have experienced, too?

I wanted to fill in the holes within my sphere, so I duplicated the image stack and then used the Process --> Binary tool in Fiji to ‘Make Binary’ and then ‘Fill Holes’. However, the image stack seems to cut really close to the edges of the 3D model to the point that it doesn’t seem watertight anymore.

Here is what I can get after the Binary tool is applied (and what I want):
Sphere_diameter_25mm_slice45

However, some slices do not have fully enclosed edges even though the 3D object is watertight:
Sphere_diameter_25mm_slice46

Is there a way for me to edit the settings in SciView so I can ledge a thicker border around the 3D object, or should I post this as a separate thread?

Thanks for your help!

Howdy,

Just noting that I’m still looking into this https://github.com/scenerygraphics/sciview/tree/voxelization.

We have seen this issue in the past and it is time to resolve it. Both of these issues are the same issue. I’ve been poking at the code, but couldn’t get a satisfactory solution in the time I had. My current plan is to step back from the fast voxelization algorithm we have and implement a slower/safer algorithm. I’ll update this thread as it progresses.

If devs are interested in digging into it, the issue arises from axis-aligned faces in the mesh. The contains/intersection tests for these are failing to return true in the limit of being completely axis aligned (hence the loss of edges in @MorphoFun’s example output).

Thanks for the reports,
Kyle

1 Like

One more update, in that branch I have correct behavior for @MorphoFun’s sphere, but still issues on @Drax’s pipebubble STL.

1 Like

Thanks a bunch, @kephale! I updated the SciView plug-in and am still getting some slices that have gaps on the edges, but not as many as before. I may need to manually fix the gaps on any remaining slices and will update this post if I’m able to find a good procedure. I tried out the Process --> Filter --> Maximum procedure to try and close the gaps and then applying Process --> Filter --> Minimum to then remove the extra border but that ended up warping the overall shape of the object.

I appreciate your help!

Hey @MorphoFun,

Since it isn’t a complete fix I didn’t start including this in the release yet. Once I get a little better idea about what is going on with the pipebubble stl, I’ll go ahead an update the SciView-Unstable update site.

Cheers
Kyle

Okay, gotcha! That makes sense. Thanks for the clarification!