Error with large models

Dear Michael,

I use BoneJ to create STL files within Fiji in the field of material sciences.

An error occurs during the calculation of the isosurface when the model is to large. The isosurface contains over 40,000,000 triangles and I have set the resampling factor to 1. It seems that the error is inside the 3D viewer after executing the marching cubes algorithm.

Error message:

(Fiji Is Just) ImageJ 2.0.0-rc-43/1.50e; Java 1.6.0_24 [64-bit]; Windows 7 6.1; 17905MB of 61000MB (29%) java.lang.NegativeArraySizeException at at<init>( at<init>( at<init>( at<init>( at customnode.CustomTriangleMesh.createGeometry( at customnode.CustomMesh.update( at customnode.CustomMesh.<init>( at customnode.CustomTriangleMesh.<init>( at customnode.CustomTriangleMesh.<init>( at org.doube.bonej.MeasureSurface.renderSurface( at at ij.IJ.runUserPlugIn( at ij.IJ.runPlugIn( at ij.Executer.runCommand( at at

Many thanks in advance,

This is almost always caused by too-large data. It happens when a 32-bit integer value (maximum value 2147483647) overflows and “wraps around” to a negative value.

Perhaps @mdoube knows a solution in this case, but in general, the workaround is to downsample or reduce the data somehow.

See also

Hi @tooor,

Try ticking the option ‘Save as binary STL’ and unticking ‘Show surface’ in BoneJ > Isosurface.

This will write your STL straight to disk without displaying it.

Let us know how you get on. We’ve written some pretty humongous STLs with it, for hi-res 3D printing. @ctrueden’s point on downsampling stands for another practical reason: if your STL is gigantic then your next step that will use the STL may suffer as a result, because all those triangles might choke your GPU or 3D printing machine and make it stall or go really slowly. Try using a resampling value of 2 or 3 (or more) and see whether it qualitatively affects your mesh.


Hi Michael,

your advice helped me to work around the error. Now I can create the STL file out of the huge image stack (2048x2048 x 909 slices).

Another question is, whether it is possible to specify a lower and upper threshold to extract a STL for each material?


The current implementation uses a single threshold along which the STL mesh is wrapped. You could consider this a value boundary, like an isobar in a weathermap. Values lower than the threshold are ‘outside’ the mesh and values higher than the threshold are ‘inside’ the mesh.

If you want your mesh to represent a different segmentation approach (e.g. min and max thresholds, textures, statistical/trainable segmentation), first extract a binary mask of the phase you wish to mesh by applying your segmentation, then run Isosurface again, on the binary mask.

1 Like