Skip to main content

Quick Reference

A condensed reference for commonly used API operations.

Application

MethodDescription
get_version()Get API version string
open_project(path)Open a project file
save_project(path="")Save current project
close_project()Close current project
undo()Undo last action
redo()Redo last undone action

Object Management

Volumes

MethodDescription
get_all_volume_names()Get all volume names
get_visible_volume_names()Get visible volume names
delete_volumes(names)Delete specified volumes
set_volumes_visible(names, visible)Set volume visibility

Masks

MethodDescription
get_all_mask_names()Get all mask names
duplicate_masks(names)Duplicate masks
delete_masks(names)Delete specified masks
isolate_masks(names)Show only specified masks

Surfaces

MethodDescription
get_all_surface_names()Get all surface names
duplicate_surfaces(names)Duplicate surfaces
delete_surfaces(names)Delete specified surfaces

Segmentation

Threshold Segmentation

threshold_params = api.ThresholdParams()
threshold_params.lower_threshold = 100
threshold_params.upper_threshold = 500
mask_name = mask_operations.threshold("volume_name", threshold_params)

Region Growing

region_grow_segmentation_params = api.RegionGrowSegmentationParams()
region_grow_segmentation_params.seed_points = [[100, 100, 50]]
mask_name = mask_operations.region_grow("volume_name", region_grow_segmentation_params)

Morphological Operations

mask_operations.morphological_operation(
["mask_name"],
api.MorphologicalOperationType.Dilate,
[2, 2, 2] # ball radius
)

AI Segmentation

ai_segmentation = app.get_ai_segmentation()

# TotalSegmentator Segmentation
ai_segmentation.set_model_type(api.AiSegmentationModelType.TotalSegmentator)

total_segmentator_params = api.TotalSegmentatorParams()
total_segmentator_params.task = "total"
total_segmentator_params.device = "gpu"

masks = ai_segmentation.run_total_segmentator(["volume_name"], total_segmentator_params)
print(f"Created {len(masks)} segmentation masks")

# MONAI Segmentation
ai_segmentation.set_model_type(api.AiSegmentationModelType.Monai)

monai_params = api.MonaiParams()
monai_params.bundle_dir = 'C:/Users/UserName/.monai/wholeBody_ct_segmentation'
monai_params.device = "gpu"

masks = ai_segmentation.run_monai(["volume_name"], monai_params)
print(f"Created {len(masks)} segmentation masks")

# nnU-Net Segmentation
ai_segmentation.set_model_type(api.AiSegmentationModelType.NnUnet)

nn_unet_params = api.NnUnetParams()
nn_unet_params.models_dir = 'C:/Users/UserName/.totalsegmentator/nnunet/results'
nn_unet_params.dataset = 'Dataset297_TotalSegmentator_total_3mm_1559subj'
nn_unet_params.configuration = '3d_fullres'
nn_unet_params.device = "gpu"

masks = ai_segmentation.run_nn_unet(["volume_name"], nn_unet_params)
print(f"Created {len(masks)} segmentation masks")

File Operations

Export Masks

mask_ops.export_mask_images_to_disk(
["mask1", "mask2"],
"C:/Output/",
"nii.gz"
)

Export Surfaces

surface_operations.export_surfaces_to_disk(
["surface1"],
"C:/Output/",
"stl"
)

Snapshots

# Save 3D view snapshot
app.save_snapshot_to_disk(
api.SnapshotType.View3D,
"C:/Output/snapshot.png",
"PNG"
)