File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 10
10
# -------------------------------------------------------------------------------
11
11
12
12
import numpy as np
13
+ import nibabel as nib
13
14
import scipy .ndimage as scn
14
15
from collections import OrderedDict
15
16
@@ -59,6 +60,36 @@ def drain_rois(img):
59
60
return out
60
61
61
62
63
+ def pick_rois (rois_img , roi_values , bg_val = 0 ):
64
+ """ Return the `rois_img` only with the ROI values from `roi_values`.
65
+ Parameters
66
+ ----------
67
+ rois_img: niimg-like
68
+
69
+ roi_values: list of int or float
70
+ The list of values from rois_img.
71
+
72
+ bg_val: int or float
73
+ The background value of `rois_img`.
74
+
75
+ Returns
76
+ -------
77
+ subset_rois_img: nibabel.Nifti2Image
78
+ """
79
+ img = read_img (rois_img )
80
+ img_data = img .get_data ()
81
+
82
+ if bg_val == 0 :
83
+ out = np .zeros (img_data .shape , dtype = img_data .dtype )
84
+ else :
85
+ out = np .ones (img_data .shape , dtype = img_data .dtype ) * bg_val
86
+
87
+ for r in roi_values :
88
+ out [img_data == r ] = r
89
+
90
+ return nib .Nifti2Image (out , affine = img .affine , header = img .header )
91
+
92
+
62
93
def largest_connected_component (volume ):
63
94
"""Return the largest connected component of a 3D array.
64
95
You can’t perform that action at this time.
0 commit comments