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. Python API
  4. Extract voxel information

Extract voxel information

Scheduled Pinned Locked Moved Python API
6 Posts 2 Posters 880 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.
  • W Offline
    W Offline
    WillHandler
    wrote on last edited by
    #1

    Hi all

    I need a way to export the voxel information to matlab, so I can mask out regions depending upon tissue type as part of my analysis. Specifically, I am looking at E field in the Duke model, but want to change the field in my plots in the bone to nan, to mask it out.

    I think it should be possible to access the voxel information and do things with it in sim4life, and would appreciate a pointer int he right direction.

    thanks

    Will

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlixPlumley
      wrote on last edited by
      #2

      You can use the Mask Filter in Field Data Tools to mask an extracted field by Material, before exporting to Matlab.

      So for example, you can specify a value (in your case NaN) to replace all the voxels which are currently assigned with Bone.

      If you use the scripter, it will look something like this, with entities being defined as everything except the Bone material in your model you want to mask out:

      			# Adding a new FieldMaskingFilter
      			inputs = [convert_to_node_data_filter.Outputs["EM E(x,y,z,f0)"]]
      			field_masking_filter = analysis.core.FieldMaskingFilter(inputs=inputs)
      			field_masking_filter.SetAllMaterials(False)
      			field_masking_filter.SetEntities(entities) 
      			field_masking_filter.UpdateAttributes()
      			document.AllAlgorithms.Add(field_masking_filter)
      

      There's more info in the html manual here:
      Data Analysis & Postprocessing > Field Data Tools > Mask Filter

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlixPlumley
        wrote on last edited by
        #3

        This may also be more useful -
        https://forum.zmt.swiss/topic/103/mask-filter-from-python-how-to-exclude-the-background-for-example

        1 Reply Last reply
        0
        • W Offline
          W Offline
          WillHandler
          wrote on last edited by
          #4

          Brilliant, exactly what I needed! Thanks so much.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            WillHandler
            wrote on last edited by
            #5

            I have implemented the filter to the data, but it does not get applied to the matlab export. I had the matlab export use the sensor output as an input previously, not sure how to make the input the output of the filter as all the things I have tried so far have not worked...

            #make the mask
            field_masking_filter = analysis.core.FieldMaskingFilter(inputs=inputs)
            field_masking_filter.SetAllMaterials(False)
            field_masking_filter.SetEntities(wanted_entities)
            field_masking_filter.UpdateAttributes()
            document.AllAlgorithms.Add(field_masking_filter)

            			outname = dirout+'\\'+sim.Name+'_masked.mat'
            			outname.replace(" ","")
            			outname = ''.join(outname.split())
            			# Adding a new MatlabExporter but after the mask has been applied
            			inputs = [field_masking_filter.GetOutput]
            			
            				
            			matlab_exporter = analysis.exporters.MatlabExporter(inputs=inputs)
            			matlab_exporter.ExportTo(outname)
            			matlab_exporter.UpdateAttributes()
            			document.AllAlgorithms.Add(matlab_exporter)
            			matlab_exporter.Update()
            
            1 Reply Last reply
            0
            • W Offline
              W Offline
              WillHandler
              wrote on last edited by
              #6

              I figured it out, made it in the gui and used to python to see what the syntax had to be

              			inputs = [field_masking_filter.Outputs["EM E(x,y,z,f0)"]]
              
              1 Reply Last reply
              0
              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