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. Analysis & Postprocessing
  4. Mask Filter from Python, How to exclude the background (for example)

Mask Filter from Python, How to exclude the background (for example)

Scheduled Pinned Locked Moved Analysis & Postprocessing
pythonmask filter
1 Posts 1 Posters 672 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.
  • SylvainS Offline
    SylvainS Offline
    Sylvain
    ZMT
    wrote on last edited by
    #1

    The API of the MaskFilter algorithm does not allow un-selecting a given entity. The only way to select "everything except one" is actually to first unselect everything and then enable all the entities (except one) again.

    Below is an example that does that for an anatomical model (or any other group of entities).

    It uses a short helper function that returns the list of all model objects (aka entities) that are within a certain model folder (aka Entity Group). This list of objects is then passed to the MaskFilter.

    import s4l_v1.analysis as analysis
    import s4l_v1.document as document
    import s4l_v1.model as model
    import itertools
    
    def all_entities_within_group(entity_group):
        '''return a list of all model entities within a given group, including all subdirectories'''
        if isinstance(entity_group, model.EntityGroup):
            return list(itertools.chain.from_iterable(
            all_entities_within_group(e) for e in entity_group.Entities))
        else:
            return [entity_group]
    
    
    vip_group = model.AllEntities()['Duke']
    entities_from_vip_model = all_entities_within_group(vip_group)
    
    
    # Creating the analysis pipeline
    # Adding a new SimulationExtractor
    simulation = document.AllSimulations["EM"]
    simulation_extractor = simulation.Results()
    
    # Adding a new EmSensorExtractor
    em_sensor_extractor = simulation_extractor["Overall Field"]
    document.AllAlgorithms.Add(em_sensor_extractor)
    
    # Adding a new FieldMaskingFilter
    inputs = [em_sensor_extractor.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_from_vip_model)
    field_masking_filter.UpdateAttributes()
    document.AllAlgorithms.Add(field_masking_filter)
    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