Complex data¶

Raw MRI uses complex numbers (real and imaginary). NiiVue can load complex data: note when you click on any location in the image both the real and imaginary components are displayed in the status bar. This is a Python port of the corresponding web page

In [1]:
import ipywidgets as widgets
from IPython.display import display
from ipyniivue import NiiVue

nv = NiiVue()




nv.load_volumes(
    [
        {
            "path": "../images/complex.nii.gz",
            "colormap": "gray",
            "opacity": 1,
            "visible": True,
        }
    ]
)


## Create drop down menu and status bar

intensity_output = widgets.HTML(" ")
@nv.on_location_change
def handle_intensity_change(location):
    """Handle location change."""
    intensity_output.value = location["string"]

slice_type_dropdown = widgets.Dropdown(
    options=[
        ("Axial", 0),
        ("Coronal", 1),
        ("Sagittal", 2),
        ("Render", 4),
        ("A+C+S+R", 3),
    ],
    value=3,
    description="Slice Type:",
)


def on_slice_type_change(change):
    """Set slice type."""
    nv.set_slice_type(change["new"])


slice_type_dropdown.observe(on_slice_type_change, names="value")

## Display

display(widgets.VBox([slice_type_dropdown, nv, intensity_output]))
/home/runner/work/ipyniivue/ipyniivue/src/ipyniivue/widget.py:1327: UserWarning: Ignored unsupported kwargs in Volume: ['visible']
  volume_objects.append(Volume(**item))
In [ ]: