Overview

ImFusion Anatomy Plugin Python Bindings

Core Functionality Areas

Anatomical Data Structures:

Registration and Processing:

Example Usage

Basic anatomical structure access:

>>> import imfusion.anatomy as anatomy
>>> import imfusion
>>> # Load anatomical structure collection
>>> asc = imfusion.open("anatomical_structures.imf")
>>> # Access individual anatomical structures
>>> num_structures = asc.num_anatomical_structures()
>>> print(f"Found {num_structures} anatomical structures")
>>> # Get structure by identifier
>>> liver = asc.anatomical_structure("liver")
>>> print(f"Liver identifier: {liver.identifier}")
>>> # Access keypoints using new interface
>>> keypoints = liver.keypoints2
>>> print(f"Available keypoints: {keypoints.keys()}")
>>> tip_point = keypoints["tip"]
>>> # Access meshes
>>> meshes = liver.meshes
>>> if "surface" in meshes:
...     surface_mesh = meshes["surface"]

Working with transformations:

>>> # Get transformation matrices
>>> world_to_local = liver.matrix_from_world
>>> local_to_world = liver.matrix_to_world
>>> # Transform keypoints to world coordinates
>>> world_tip = local_to_world @ tip_point

Registration example:

>>> # Load two anatomical structure collections
>>> fixed_asc = imfusion.open("template.imf")
>>> moving_asc = imfusion.open("patient.imf")
>>> # Create registration algorithm
>>> registration = anatomy.ASCRegistration(fixed_asc, moving_asc)
>>> registration.registration_method = anatomy.ASCRegistration.RegistrationMethod.PointsAndPlanes
>>> # Compute registration
>>> registration.compute()

Creating anatomical structures from label maps:

>>> # Load label image
>>> label_image = imfusion.open("segmentation.nii")
>>> # Define label mappings
>>> label_mapping = {1: "liver", 2: "kidney", 3: "spleen"}
>>> # Create generic ASC from label map
>>> asc = anatomy.generic_asc_from_label_map(label_image, label_mapping)
>>> # Access created structures
>>> liver = asc.anatomical_structure("liver")

Shape model generation:

>>> # Load mean shape template
>>> mean_shape = imfusion.open("mean_template.imf")
>>> # Create shape model generator
>>> shape_model_gen = anatomy.GenerateLinearShapeModel(mean_shape)
>>> # Configure input directory with training data
>>> shape_model_gen.p_inputDirectory = "/path/to/training/data"
>>> # Generate shape model
>>> results = shape_model_gen()
>>> shape_model = results["shape_model"]
>>> updated_mean = results.get("mean")

For detailed documentation of specific classes and functions, use Python’s built-in help() function or access the docstrings directly.

Note: This module requires the ImFusion Anatomy plugin to be properly installed.