Skip to content

Instantly share code, notes, and snippets.

@jcohenadad
Last active May 30, 2024 14:20
Show Gist options
  • Save jcohenadad/c5ef04fb77b303d8e582c6d2f12b8508 to your computer and use it in GitHub Desktop.
Save jcohenadad/c5ef04fb77b303d8e582c6d2f12b8508 to your computer and use it in GitHub Desktop.

Custom FSLeyes scene time series

Set up a custom scene using the FSLeyes API via a custom Python script.

The scene consists of two Ortho views at the top, and one time series at the bottom. I used it to draw a mask to compute velocity encoding. The velocity image and the overlaid mask are shown on the left and the anatomical image on the right.

Command

$ fsleyes -S -r custom_fsleyes_scene_timeseries.py <VELOCITY> <ANAT> <MASK>

Custom script

# Show two OrthoPanels next to each other
ortho_left = frame.addViewPanel(OrthoPanel)
ortho_left.defaultLayout()
ortho_right = frame.addViewPanel(OrthoPanel)
ortho_right.defaultLayout()

# Show one TimeSeriesPanels at the bottom
timeseriespanel_bottom = frame.addViewPanel(TimeSeriesPanel)
timeseriespanel_bottom.defaultLayout()

# Keep only axial plane for the ortho_left
ortho_left.sceneOpts.showXCanvas = False
ortho_left.sceneOpts.showYCanvas = False

# Keep only axial plane for the ortho_right
ortho_right.sceneOpts.showXCanvas = False
ortho_right.sceneOpts.showYCanvas = False

# Get list of loaded overlays based on the files listed in the command line
velocity, anat, mask = overlayList

# Get Display objects for each image and for each view
velocity_leftdisplay  = ortho_left.displayCtx.getDisplay(velocity)
velocity_rightdisplay = ortho_right.displayCtx.getDisplay(velocity)
velocity_timeseriespanel = timeseriespanel_bottom.displayCtx.getDisplay(velocity)
anat_leftdisplay  = ortho_left.displayCtx.getDisplay(anat)
anat_rightdisplay = ortho_right.displayCtx.getDisplay(anat)
anat_timeseriespanel = timeseriespanel_bottom.displayCtx.getDisplay(anat)
mask_leftdisplay  = ortho_left.displayCtx.getDisplay(mask)
mask_rightdisplay = ortho_right.displayCtx.getDisplay(mask)
mask_timeseriespanel = timeseriespanel_bottom.displayCtx.getDisplay(mask)

# Show anat to the left and velocity to the right and on the time series panel
velocity_leftdisplay.enabled  = True
velocity_rightdisplay.enabled = False
velocity_timeseriespanel.enabled = True
anat_leftdisplay.enabled  = False
anat_rightdisplay.enabled = True
anat_timeseriespanel.enabled = False
mask_leftdisplay.enabled  = True
mask_rightdisplay.enabled = False
mask_timeseriespanel.enabled = False

# Change display space for the right OrthoPanel to t2ax
ortho_right.displayCtx.displaySpace = velocity

Useful ressources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment