Mask demo¶

This Python script emulates the mask web page

In [1]:
# Import necessary libraries
import ipywidgets as widgets
from IPython.display import display
from ipyniivue import NiiVue, SliceType


# Create a NiiVue instance with specific options
nv = NiiVue(show_3d_crosshair=True)

# Load the volumes
volumes = [
    {
        "path": "../images/fslmean.nii.gz",
    },
    {
        "path": "../images/fslt.nii.gz",
        "colormap": "redyell",
        "cal_min": 0.05,
        "cal_max": 5.05,
        "opacity": 0.9,
    },
]

nv.load_volumes(volumes)

# Set the slice type to render (3D view)
nv.set_slice_type(SliceType.RENDER)

# Set the clip plane
nv.set_clip_plane(0.15, 270, 0)

# Set the render azimuth and elevation
nv.set_render_azimuth_elevation(45, 45)

## Create interactive checkbox

# Create a checkbox to toggle background masks overlays
background_masks_checkbox = widgets.Checkbox(
    value=False,
    description="Background masks overlay",
    disabled=False,
)


# Function to handle checkbox changes
def on_background_masks_change(change):
    """Set background mask overlay."""
    nv.background_masks_overlays = change.new


# Observe changes to the checkbox
background_masks_checkbox.observe(on_background_masks_change, names="value")

## Display all

display(background_masks_checkbox)
display(nv)
In [ ]: