Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. How to Script the Import a Segmented NIfTI Volume as a Solid in Sim4Life?

How to Script the Import a Segmented NIfTI Volume as a Solid in Sim4Life?

Scheduled Pinned Locked Moved Sim4Life
imagemodelpython
3 Posts 2 Posters 236 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andrea_h
    wrote on last edited by Sylvain
    #1

    Hello everyone,

    I am currently working with a segmented volume in .nifti format and would like to import it as a solid in Sim4Life using scripting. I have heard that the iSeg segmentation tool within Sim4Life might be useful for this process. Could anyone provide guidance, scripts, or tips on how to achieve this?

    Thank you in advance!

    1 Reply Last reply
    0
    • brynB Online
      brynB Online
      bryn
      ZMT
      wrote on last edited by bryn
      #2

      Hi

      To import the nifti file as a labelfield, with label names and colors, it is helpful to have a descriptor file. Sim4Life supports the iSEG format (.txt) and Slicer 3D color table (.ctbl).

      The iSEG "tissue list" format is very simple. For example, the following would describe a segmentation with three labels (N3). The V7 refers to a version of the format. Each line starting with "C" lists the labels in order 1, 2, 3, with RGBA colors in floating point values followed by the name, e.g., Bone has label=1, color=(0, 0, 255) and alpha=127.

       V7
       N3
       C0.00 0.00 1.00 0.50 Bone
       C0.00 1.00 0.00 0.50 Fat
       C1.00 0.00 0.00 0.50 Skin
      

      To import the labelfield and extract the solids, you can using following script.

      # script to import the labelfield and extract surfaces
      from s4l_v1.model.image import ExtractSurface, ImportLabelField
      
      def import_as_solid(nii_path: str, tissue_list_path: str, min_edge_length: float = 0.5):
          labelfield = ImportLabelField(nii_path, tissue_list_path)
          solids = ExtractSurface(label_field=labelfield, min_edge_length=min_edge_length)
          return solids
      

      Note, if you are looking for the "Import Voxels [as Solid]" dialog in the GUI, you cannot directly use nifti files. However, the proposed workflow produces smoother solids (closed triangle meshes) - I would argue for most purposes a better result.

      1 Reply Last reply
      1
      • brynB Online
        brynB Online
        bryn
        ZMT
        wrote on last edited by
        #3

        Here is a simple implementation to write an iSEG tissue list file, given a dictionary mapping the label index to a name:
        https://github.com/dyollb/s4l-scripts/blob/df8e2241f87ca91d71138e9d2b3d4336dadb82dc/src/anisotropic_conductivity/load_labels.py#L44

        1 Reply Last reply
        1
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Search