macapype 0.6__tar.gz → 0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- macapype-0.7/LICENCE.txt +7 -0
- {macapype-0.6 → macapype-0.7}/PKG-INFO +7 -3
- {macapype-0.6 → macapype-0.7}/README.md +6 -2
- {macapype-0.6 → macapype-0.7}/docs/conf.py +1 -1
- macapype-0.7/macapype/_version.py +1 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/IterREGBET.sh +5 -3
- {macapype-0.6 → macapype-0.7}/macapype/nodes/correct_bias.py +1 -1
- {macapype-0.6 → macapype-0.7}/macapype/nodes/prepare.py +11 -2
- {macapype-0.6 → macapype-0.7}/macapype/nodes/register.py +14 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/segment.py +4 -3
- {macapype-0.6 → macapype-0.7}/macapype/nodes/surface.py +50 -8
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/full_pipelines.py +591 -624
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/prepare.py +92 -29
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/rename.py +144 -105
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/segment.py +10 -33
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/surface.py +630 -10
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/tests/test_full_pipelines.py +9 -61
- {macapype-0.6 → macapype-0.7}/macapype/utils/data_test_servers.json +1 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/templates.json +6 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/tests/test_utils_nodes.py +32 -5
- {macapype-0.6 → macapype-0.7}/macapype/utils/utils_params.py +67 -64
- {macapype-0.6 → macapype-0.7}/macapype.egg-info/PKG-INFO +7 -3
- {macapype-0.6 → macapype-0.7}/macapype.egg-info/SOURCES.txt +2 -0
- {macapype-0.6 → macapype-0.7}/macapype.egg-info/top_level.txt +1 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon0_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon0_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon1_0p6_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon1_0p6_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon1_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon1_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon2_0p6_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon2_0p6_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon2_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon2_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon2_ants_quick.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon3_0p6_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon3_0p6_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon3_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon3_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon3_ants_quick.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon_ants.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon_ants_4animal.json +4 -1
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_baboon_ants_quick.json +9 -9
- macapype-0.7/workflows/params_segment_baboon_spm.json +74 -0
- macapype-0.7/workflows/params_segment_baboon_spm_4animal.json +95 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_human_1mm_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_human_2mm_ants_4animal.json +9 -9
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_macaque_0p5_ants.json +9 -9
- macapype-0.7/workflows/params_segment_macaque_0p5_ants_4animal.json +149 -0
- macapype-0.7/workflows/params_segment_macaque_0p5_spm.json +147 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_macaque_ants.json +9 -9
- macapype-0.7/workflows/params_segment_macaque_ants_4animal.json +148 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_macaque_ants_quick.json +9 -9
- macapype-0.7/workflows/params_segment_macaque_spm.json +148 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_marmo_ants.json +13 -10
- macapype-0.7/workflows/params_segment_marmo_ants_4animal.json +74 -0
- macapype-0.7/workflows/params_segment_marmo_spm.json +90 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_marmot2_ants.json +9 -9
- macapype-0.6/workflows/params_segment_marmo_ants_4animal.json → macapype-0.7/workflows/params_segment_marmot2_ants_4animal.json +15 -12
- {macapype-0.6 → macapype-0.7}/workflows/segment_pnh.py +31 -27
- macapype-0.6/LICENCE.txt +0 -11
- macapype-0.6/macapype/_version.py +0 -1
- macapype-0.6/workflows/params_segment_baboon_spm.json +0 -72
- macapype-0.6/workflows/params_segment_macaque_0p5_ants_4animal.json +0 -80
- macapype-0.6/workflows/params_segment_macaque_0p5_spm.json +0 -69
- macapype-0.6/workflows/params_segment_macaque_ants_4animal.json +0 -78
- macapype-0.6/workflows/params_segment_macaque_spm.json +0 -73
- macapype-0.6/workflows/params_segment_marmo_spm.json +0 -76
- {macapype-0.6 → macapype-0.7}/MANIFEST.in +0 -0
- {macapype-0.6 → macapype-0.7}/examples_doc/plot_segment_sphinx_macaque_ants_based.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/__init__.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/CropVolume.sh +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/NMT_subject_align +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/NMT_subject_align.csh +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/T1xT2BET.sh +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/T1xT2BiasFieldCorrection.sh +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/bash/atlasBREX.sh +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/__init__.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/denoise.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/extract_brain.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/pad.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/tests/test_segment.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/nodes/tests/test_surface.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/__init__.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/correct_bias.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/extract_brain.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/register.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/tests/test_prepare.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/pipelines/tests/test_surface_pipelines.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/__init__.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/misc.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/regex_subs.json +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/subs.json +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/tests/test_misc.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/tests/test_utils_bids.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/tests/test_utils_tests.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/utils_bids.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/utils_nodes.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/utils_spm.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype/utils/utils_tests.py +0 -0
- {macapype-0.6 → macapype-0.7}/macapype.egg-info/dependency_links.txt +0 -0
- {macapype-0.6 → macapype-0.7}/macapype.egg-info/entry_points.txt +0 -0
- {macapype-0.6 → macapype-0.7}/macapype.egg-info/requires.txt +0 -0
- {macapype-0.6 → macapype-0.7}/pyproject.toml +0 -0
- {macapype-0.6 → macapype-0.7}/setup.cfg +0 -0
- {macapype-0.6 → macapype-0.7}/setup.py +0 -0
- {macapype-0.6 → macapype-0.7}/workflows/__init__.py +0 -0
- {macapype-0.6 → macapype-0.7}/workflows/params_segment_chimp_ants.json +0 -0
- {macapype-0.6 → macapype-0.7}/workflows/segment_from_mask_pnh_ants_based.py +0 -0
- {macapype-0.6 → macapype-0.7}/workflows/segment_pnh_regis.py +0 -0
- {macapype-0.6 → macapype-0.7}/workflows/which_spm.py +0 -0
macapype-0.7/LICENCE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2021 Macatools
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: macapype
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7
|
|
4
4
|
Summary: Pipeline for anatomic processing for macaque
|
|
5
5
|
Author: Macatools team
|
|
6
6
|
Maintainer: Macapype developers
|
|
@@ -55,14 +55,14 @@ python setup.py develop
|
|
|
55
55
|
|
|
56
56
|
# Docker image
|
|
57
57
|
```shell
|
|
58
|
-
docker pull macatools/macapype
|
|
58
|
+
docker pull macatools/macapype:latest
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
# Documentation
|
|
62
62
|
|
|
63
63
|
https://macatools.github.io/macapype/
|
|
64
64
|
|
|
65
|
-
#
|
|
65
|
+
# External documentation related to project
|
|
66
66
|
|
|
67
67
|
[A guide for PNH MRI processing](https://github.com/PRIME-RE/prime-re.github.io/wiki), and in particular, the session on [structural MRI processing](https://github.com/PRIME-RE/prime-re.github.io/wiki/Structural-processing)
|
|
68
68
|
|
|
@@ -73,3 +73,7 @@ https://macatools.github.io/macapype/
|
|
|
73
73
|
|
|
74
74
|
The macapype_users can be be found [here](https://framateam.org/signup_user_complete/?id=ebtxf45nmiyqmkm8e6oh9qjsoe) (requires a framateam/framagit account, but should be accessible with a github or bitbucket account)
|
|
75
75
|
|
|
76
|
+
|
|
77
|
+
# Contribution to project
|
|
78
|
+
|
|
79
|
+
Are you willing to contribute to the project? See the instructions in [CONTRIBUTING.md](https://github.com/macatools/macapype/blob/master/CONTRIBUTING.md)
|
|
@@ -16,14 +16,14 @@ python setup.py develop
|
|
|
16
16
|
|
|
17
17
|
# Docker image
|
|
18
18
|
```shell
|
|
19
|
-
docker pull macatools/macapype
|
|
19
|
+
docker pull macatools/macapype:latest
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
# Documentation
|
|
23
23
|
|
|
24
24
|
https://macatools.github.io/macapype/
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# External documentation related to project
|
|
27
27
|
|
|
28
28
|
[A guide for PNH MRI processing](https://github.com/PRIME-RE/prime-re.github.io/wiki), and in particular, the session on [structural MRI processing](https://github.com/PRIME-RE/prime-re.github.io/wiki/Structural-processing)
|
|
29
29
|
|
|
@@ -34,3 +34,7 @@ https://macatools.github.io/macapype/
|
|
|
34
34
|
|
|
35
35
|
The macapype_users can be be found [here](https://framateam.org/signup_user_complete/?id=ebtxf45nmiyqmkm8e6oh9qjsoe) (requires a framateam/framagit account, but should be accessible with a github or bitbucket account)
|
|
36
36
|
|
|
37
|
+
|
|
38
|
+
# Contribution to project
|
|
39
|
+
|
|
40
|
+
Are you willing to contribute to the project? See the instructions in [CONTRIBUTING.md](https://github.com/macatools/macapype/blob/master/CONTRIBUTING.md)
|
|
@@ -129,7 +129,7 @@ html_theme_options = {
|
|
|
129
129
|
#("Github", "https://github.com/macatools/macapype", True),
|
|
130
130
|
#]
|
|
131
131
|
'navbar_links': [
|
|
132
|
-
("Github", "https://github.com/
|
|
132
|
+
("Github", "https://github.com/macatools/macapype", True),
|
|
133
133
|
]
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.7'
|
|
@@ -278,11 +278,13 @@ for ((i = 1 ; i <= $NITER ; i++)); do
|
|
|
278
278
|
|
|
279
279
|
# Extra whole-head non-linear registration, if wanted
|
|
280
280
|
if [[ -n $REF_WHOLE ]] && [[ $i == $NITER ]]; then
|
|
281
|
-
echo "FNIRT..."
|
|
281
|
+
echo "FNIRT..." 1>&2
|
|
282
282
|
"${FSLPREFIX}fnirt" --in=$IN_WHOLE --ref=$REF_WHOLE --aff=$I2R_XFM --iout=${WARP[WH_OUT]} --cout=${WARP[WH_WARP]} # compute warp
|
|
283
|
-
|
|
283
|
+
#"${FSLPREFIX}fnirt" --in=$IN_WHOLE --ref=$REF_WHOLE --aff=$I2R_XFM --iout=${WARP[WH_OUT]} --cout=${WARP[WH_WARP]} --miter=5,3 --subsamp=4,2 --infwhm=6,4 --reffwhm=4,2 --estint=false --applyrefmask=false --applyinmask=false # compute warp
|
|
284
|
+
#"${FSLPREFIX}fnirt" --in=$IN_WHOLE --ref=$REF_WHOLE --aff=$I2R_XFM --iout=${WARP[WH_OUT]} --cout=${WARP[WH_WARP]} --miter=1 --subsamp=4 --infwhm=6 --reffwhm=4 --estint=false --applyrefmask=false --applyinmask=false # compute warp
|
|
285
|
+
echo "Inverting warp..." 1>&2
|
|
284
286
|
"${FSLPREFIX}invwarp" -r $IN_WHOLE -w ${WARP[WH_WARP]} -o ${WARP[WH_INVWARP]}
|
|
285
|
-
echo "Applying inverse warp..."
|
|
287
|
+
echo "Applying inverse warp..." 1>&2
|
|
286
288
|
"${FSLPREFIX}applywarp" --ref=$IN_WHOLE --in=${TMP[REF_MASK]} --out=$IN_OUT_MASK --warp=${WARP[WH_INVWARP]} --interp=nn
|
|
287
289
|
else
|
|
288
290
|
"${FSLPREFIX}flirt" -in ${TMP[REF_MASK]} -ref $IN_WHOLE -out $IN_OUT_MASK -interp nearestneighbour -applyxfm -init $R2I_XFM # move brain mask to in_file
|
|
@@ -273,7 +273,7 @@ class CropVolume(CommandLine):
|
|
|
273
273
|
|
|
274
274
|
###############################################################################
|
|
275
275
|
# Equivalent of flirt_average in FSL
|
|
276
|
-
def average_align(list_img, reorient=False):
|
|
276
|
+
def average_align(list_img, reorient=False, max_index=None):
|
|
277
277
|
|
|
278
278
|
import os
|
|
279
279
|
import nibabel as nib
|
|
@@ -299,7 +299,16 @@ def average_align(list_img, reorient=False):
|
|
|
299
299
|
data_0_shape = data_0.shape
|
|
300
300
|
list_data = [data_0]
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
if max_index is not None:
|
|
303
|
+
assert max_index < len(list_img), f"Error with {max_index=}"
|
|
304
|
+
|
|
305
|
+
for i, img in enumerate(list_img[1:], 1):
|
|
306
|
+
|
|
307
|
+
if max_index is not None:
|
|
308
|
+
if i > max_index:
|
|
309
|
+
print(f"Iter {i=} higher than {max_index=}")
|
|
310
|
+
continue
|
|
311
|
+
|
|
303
312
|
data_orig_shape = nib.load(img).get_fdata().shape
|
|
304
313
|
if data_orig_shape != data_0_shape:
|
|
305
314
|
print(f"**** Warning , original image shape \
|
|
@@ -221,6 +221,12 @@ class IterREGBETOutputSpec(TraitedSpec):
|
|
|
221
221
|
exists=True,
|
|
222
222
|
desc="inv_transfo_file")
|
|
223
223
|
|
|
224
|
+
nonlin_warp_file = File(
|
|
225
|
+
desc="nonlin_warp_file")
|
|
226
|
+
|
|
227
|
+
nonlin_invwarp_file = File(
|
|
228
|
+
desc="nonlin_invwarp_file")
|
|
229
|
+
|
|
224
230
|
|
|
225
231
|
class IterREGBET(CommandLine):
|
|
226
232
|
"""
|
|
@@ -334,8 +340,16 @@ class IterREGBET(CommandLine):
|
|
|
334
340
|
outfile = self._gen_outfilename()
|
|
335
341
|
|
|
336
342
|
outputs["warp_file"] = os.path.abspath(outfile + ".nii.gz")
|
|
343
|
+
|
|
337
344
|
outputs["transfo_file"] = os.path.abspath(outfile + ".xfm")
|
|
338
345
|
outputs["inv_transfo_file"] = os.path.abspath(outfile + "_inverse.xfm")
|
|
346
|
+
|
|
347
|
+
if isdefined(self.inputs.refw_file) and self.inputs.k is True:
|
|
348
|
+
outputs["nonlin_warp_file"] = \
|
|
349
|
+
os.path.abspath(outfile + "_Warp.nii.gz")
|
|
350
|
+
outputs["nonlin_invwarp_file"] = \
|
|
351
|
+
os.path.abspath(outfile + "_InverseWarp.nii.gz")
|
|
352
|
+
|
|
339
353
|
return outputs
|
|
340
354
|
|
|
341
355
|
|
|
@@ -248,15 +248,16 @@ def merge_imgs(list_img_files):
|
|
|
248
248
|
path, fname, ext = split_f(img_file)
|
|
249
249
|
img = nib.load(img_file)
|
|
250
250
|
img_data = img.get_fdata()
|
|
251
|
-
new_img_data = np.zeros(shape=img_data.shape)
|
|
252
|
-
new_img_data[img_data != 0]
|
|
251
|
+
new_img_data = np.zeros(shape=img_data.shape, dtype=np.int32)
|
|
252
|
+
new_img_data[img_data != 0] = 1
|
|
253
253
|
|
|
254
254
|
else:
|
|
255
255
|
img_data = nib.load(img_file).get_fdata()
|
|
256
|
+
|
|
256
257
|
assert img_data.shape == new_img_data.shape, \
|
|
257
258
|
"Error, shapes {} != {}".format(img_data.shape,
|
|
258
259
|
new_img_data.shape)
|
|
259
|
-
new_img_data[img_data != 0]
|
|
260
|
+
new_img_data[img_data != 0] = 1
|
|
260
261
|
|
|
261
262
|
# creating indexed_mask
|
|
262
263
|
merged_img = nib.Nifti1Image(dataobj=new_img_data,
|
|
@@ -4,20 +4,24 @@ from nipype.interfaces.base import (
|
|
|
4
4
|
from nipype.interfaces.afni.base import AFNICommandBase
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
def getLargestCC(segmentation):
|
|
8
|
+
|
|
9
|
+
from skimage.measure import label
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
labels = label(segmentation)
|
|
13
|
+
assert labels.max() != 0 # assume at least 1 CC
|
|
14
|
+
largestCC = labels == np.argmax(np.bincount(labels.flat)[1:])+1
|
|
15
|
+
return largestCC, labels
|
|
16
|
+
|
|
17
|
+
|
|
7
18
|
def keep_gcc(nii_file):
|
|
8
19
|
import os
|
|
9
20
|
import nibabel as nib
|
|
10
21
|
import numpy as np
|
|
11
22
|
from nipype.utils.filemanip import split_filename as split_f
|
|
12
23
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
from skimage.measure import label
|
|
16
|
-
|
|
17
|
-
labels = label(segmentation)
|
|
18
|
-
assert labels.max() != 0 # assume at least 1 CC
|
|
19
|
-
largestCC = labels == np.argmax(np.bincount(labels.flat)[1:])+1
|
|
20
|
-
return largestCC, labels
|
|
24
|
+
from macapype.nodes.surface import getLargestCC
|
|
21
25
|
|
|
22
26
|
# nibabel (nifti -> np.array)
|
|
23
27
|
img = nib.load(nii_file)
|
|
@@ -50,6 +54,44 @@ def keep_gcc(nii_file):
|
|
|
50
54
|
return gcc_nii_file
|
|
51
55
|
|
|
52
56
|
|
|
57
|
+
def keep_gcc_by_index(nii_file):
|
|
58
|
+
import os
|
|
59
|
+
import nibabel as nib
|
|
60
|
+
import numpy as np
|
|
61
|
+
from nipype.utils.filemanip import split_filename as split_f
|
|
62
|
+
|
|
63
|
+
from macapype.nodes.surface import getLargestCC
|
|
64
|
+
|
|
65
|
+
# nibabel (nifti -> np.array)
|
|
66
|
+
img = nib.load(nii_file)
|
|
67
|
+
data = img.get_fdata().astype(np.int16)
|
|
68
|
+
|
|
69
|
+
path, fname, ext = split_f(nii_file)
|
|
70
|
+
|
|
71
|
+
print(np.unique(data))
|
|
72
|
+
|
|
73
|
+
new_data = np.zeros(data.shape, data.dtype)
|
|
74
|
+
|
|
75
|
+
for index in np.unique(data)[1:]:
|
|
76
|
+
data_data_bin_index = np.zeros(data.shape, data.dtype)
|
|
77
|
+
data_data_bin_index[data == index] = 1
|
|
78
|
+
|
|
79
|
+
if np.sum(data_data_bin_index):
|
|
80
|
+
gcc_index_data, _ = getLargestCC(data_data_bin_index)
|
|
81
|
+
new_data[gcc_index_data] = index
|
|
82
|
+
|
|
83
|
+
# nibabel (np.array -> nifti)
|
|
84
|
+
new_img = nib.Nifti1Image(dataobj=new_data,
|
|
85
|
+
header=img.header,
|
|
86
|
+
affine=img.affine)
|
|
87
|
+
|
|
88
|
+
gcc_nii_file = os.path.abspath(fname + "_gcc" + ext)
|
|
89
|
+
|
|
90
|
+
nib.save(new_img, gcc_nii_file)
|
|
91
|
+
|
|
92
|
+
return gcc_nii_file
|
|
93
|
+
|
|
94
|
+
|
|
53
95
|
def merge_tissues(dseg_file, keep_indexes):
|
|
54
96
|
|
|
55
97
|
import os
|