-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualization.py
36 lines (29 loc) · 1.45 KB
/
visualization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from nilearn import plotting
import nibabel as nib
import matplotlib.pyplot as plt
import numpy as np
def plot_image(input_image: nib.Nifti1Image, display_mode: str = 'ortho', cmap: str = 'gray') -> None:
"""
Display a NIfTI image using Nilearn's plotting capabilities.
Parameters:
input_image (nibabel.nifti1.Nifti1Image): The NIfTI image to be displayed.
display_mode (str): The display mode for the image. Can be 'ortho', 'x', 'y', or 'z' (default: 'ortho').
cmap (str): The colormap to use for displaying the image (default: 'gray').
Returns:
None
"""
plotting.plot_anat(input_image, display_mode=display_mode, cmap=cmap)
plt.show()
def plot_image_with_mask(input_image: nib.Nifti1Image, mask_image: nib.Nifti1Image, display_mode: str = 'ortho', cmap: str = 'gray') -> None:
"""
Display a NIfTI image with an overlay mask using Nilearn's plotting capabilities.
Parameters:
input_image (nibabel.nifti1.Nifti1Image): The background image to be displayed.
mask_image (nibabel.nifti1.Nifti1Image): The binary mask to be overlayed on the background image.
display_mode (str): The display mode for the image. Can be 'ortho', 'x', 'y', or 'z' (default: 'ortho').
cmap (str): The colormap to use for displaying the background image (default: 'gray').
Returns:
None
"""
plotting.plot_roi(roi_img=mask_image, bg_img=input_image, display_mode=display_mode, cmap=cmap, alpha=0.5)
plt.show()