Skip to content

Commit fad82cd

Browse files
committed
RF: Handle overlay in .orthoview()
1 parent 989ac26 commit fad82cd

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

nibabel/spatialimages.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,14 @@ def __getitem__(self, idx):
589589
"slicing image array data with `img.dataobj[slice]` or "
590590
"`img.get_fdata()[slice]`")
591591

592-
def orthoview(self):
592+
def orthoview(self, overlay=None, **kwargs):
593593
"""Plot the image using OrthoSlicer3D
594594
595+
Parameters
596+
----------
597+
overlay : ``spatialimage`` instance
598+
Image to be plotted as overlay. Default: None
599+
595600
Returns
596601
-------
597602
viewer : instance of OrthoSlicer3D
@@ -603,8 +608,12 @@ def orthoview(self):
603608
consider using viewer.show() (equivalently plt.show()) to show
604609
the figure.
605610
"""
606-
return OrthoSlicer3D(self.dataobj, self.affine,
607-
title=self.get_filename())
611+
ortho = OrthoSlicer3D(self.dataobj, self.affine,
612+
title=self.get_filename())
613+
if overlay is not None:
614+
ortho.set_overlay(overlay, **kwargs)
615+
616+
return ortho
608617

609618
def as_reoriented(self, ornt):
610619
"""Apply an orientation change and return a new image

nibabel/viewers.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,29 @@ def alpha(self, alpha):
331331
self._alpha = alpha
332332
self.draw()
333333

334-
def set_overlay(self, data, affine=None, threshold=None, cmap='viridis'):
334+
def set_overlay(self, data, affine=None, threshold=None, cmap='viridis',
335+
alpha=0.7):
336+
""" Sets `data` as overlay for currently plotted image
337+
338+
Parameters
339+
----------
340+
data : array-like
341+
The data that will be overlayed on the slicer. Should have 3+
342+
dimensions.
343+
affine : array-like or None, optional
344+
Affine transform for the provided data. This is used to determine
345+
how the data should be sliced for plotting into the sagittal,
346+
coronal, and axial view axes. If this does not match the currently
347+
plotted slicer the provided data will be resampled.
348+
threshold : float or None, optional
349+
Threshold for overlay data; values below this threshold will not
350+
be displayed. Default: None
351+
cmap : str, optional
352+
The Colormap instance or registered colormap name used to map
353+
scalar data to colors. Default: 'viridis'
354+
alpha : [0, 1] float, optional
355+
Set the alpha value used for blending. Default: 0.7
356+
"""
335357
if affine is None:
336358
try: # did we get an image?
337359
affine = data.affine
@@ -384,8 +406,7 @@ def set_overlay(self, data, affine=None, threshold=None, cmap='viridis'):
384406

385407
# set transparency and new cmap
386408
self._overlay.cmap = cmap
387-
for im in self._overlay._ims:
388-
im.set_alpha(0.7)
409+
self._overlay.alpha = alpha
389410

390411
# no double cross-hairs (they get confused when we have linked orthos)
391412
for cross in self._overlay._crosshairs:

0 commit comments

Comments
 (0)