Skip to content

Commit 863a655

Browse files
committed
RF: Handle overlay in .orthoview()
1 parent 714e905 commit 863a655

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
@@ -332,7 +332,29 @@ def alpha(self, alpha):
332332
self._alpha = alpha
333333
self.draw()
334334

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

386408
# set transparency and new cmap
387409
self._overlay.cmap = cmap
388-
for im in self._overlay._ims:
389-
im.set_alpha(0.7)
410+
self._overlay.alpha = alpha
390411

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

0 commit comments

Comments
 (0)