neurolabusc / surf-ice

GLSL surface rendering source code. Compiled versions available from NITRC. Loads 3DS, CTM, DXF, FreeSurfer, GII (GIfTI), GTS, LWO2, MS3D, MZ3, NV (BrainNetViewer), OBJ, OFF, PLY, STL, VTK. Tractography formats include BFloat, PDB, TCK, TRK, and VTK. Also NIfTI format voxelwise images.
https://www.nitrc.org/plugins/mwiki/index.php/surfice:MainPage
BSD 2-Clause "Simplified" License
104 stars 23 forks source link

CLI way of converting volumetric images to mesh #9

Closed TheChymera closed 6 years ago

TheChymera commented 6 years ago

Surf-ice has become my go-to program for converting volumetric images to meshes. This is mainly because I generally need 1-layer detection, and the more advanced features offered by bulkier and less trivial-to-compile packages such as iso2mesh are irrelevant for my purposes.

I'd like, however, to be able to access this feature from the CLI. This is not just for conveninence, but also because sometimes determining the ideal parameters for conversion is a matter of trial and error - which can sometimes border on unfeasible without batch mode.

Is there any way to do this?

neurolabusc commented 6 years ago

Labeled as enhancement - should be easy to add to next version. In the meantime, if you have SPM and Matlab installed you can script nii_nii2objMesh which was used to prototype the Surfice functions. Note the Matlab code uses Matlab's proprietary reducepatch that is fast and nicely adaptive but can sometimes convert manifold meshes to non-manifold. This can result in meshes that exhibit little gaps/tearing artifacts.

TheChymera commented 6 years ago

Thanks for the interim solution suggestion. But at this point I feel MATLAB simply isn't worth the hassle.

Let me know when surf-ice is natively providing this!

neurolabusc commented 6 years ago

The latest source code contains this feature. I have also added compiled versions for Linux and MacOS (but not Windows) to the current pre-release: https://github.com/neurolabusc/surf-ice/releases/tag/v1.0.20180202

MESHCREATE(niiname, meshname: string; threshold, decimateFrac: single; minimumClusterVox, smoothStyle: integer); Convert a NIfTI voxel-based image into a mesh
 niiname: filename of NIfTI-format volumetric image
 meshname: name of mesh to generate (.mz3, .gii or .obj format)
 threshold: only voxels brighter than this value survive, for example if NIfTI is Z-score then 4.1 means only voxels with z >= 4.1 survive (use 1/0 for 50% intensity)
 decimateFrac: a value from 0.01..1 for mesh reduction, e.g. 0.1 decimates 90% of the faces
 minimumClusterVox: only clusters with at least this many voxels survive
 smoothstyle: 0=raw, 1=masked_smooth, 2=smooth
Examples:
  meshcreate('/Users/rorden/avg152T1.nii','mymesh.mz3',0.5,0.3,1,2);
  meshcreate('/Users/rorden/bT1_mprage_2.nii','myT1mesh.mz3',1/0,0.3,1,2);

Please test and close this issue if you want. Do tell me if any of your images are converted with reverse faces (e.g. when you clip the volume the inside appears bright/shiny and the outside appears dark/matte). I have added a primitive attempt to detect triangle winding, but I do not think it works with all spatial transformation matrices. If you do get reversed faces, I have added the script command meshreversefaces() that does the same thing as the Advanced/ReverseFaces menu item.