Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-science
analysis
C-MORE brain MRI
Commits
1ea0a651
Commit
1ea0a651
authored
Jun 16, 2021
by
Christoph Arthofer
Browse files
Upload New File
parent
04f3aef6
Changes
1
Hide whitespace changes
Inline
Side-by-side
OB_pipeline/cmore_segSize.py
0 → 100644
View file @
1ea0a651
#!/usr/bin/env python
# Author: Christoph Arthofer
# Copyright: FMRIB 2021
import
nibabel
as
nib
import
numpy
as
np
import
pandas
as
pd
id_paths
=
[
'IDs.txt'
]
label_path_temp
=
"/path/to/labels/OB_labels_to_%s.nii.gz"
vols
=
[]
ids
=
[]
tbvs
=
[]
for
id_path
in
id_paths
:
df_ids
=
pd
.
read_csv
(
id_path
,
header
=
None
,
names
=
[
'subject_ID'
],
dtype
=
{
'subject_ID'
:
str
})
ls_ids
=
df_ids
[
'subject_ID'
].
tolist
()
for
id
in
ls_ids
:
img_path
=
label_path_temp
%
id
label_nib
=
nib
.
load
(
img_path
)
header
=
label_nib
.
header
label_arr
=
label_nib
.
get_fdata
()
mask_count
=
np
.
sum
(
label_arr
)
vol
=
mask_count
*
np
.
prod
(
header
[
'pixdim'
][
1
:
4
])
print
(
'id:'
,
id
,
' pixdim:'
,
header
[
'pixdim'
],
' volume:'
,
vol
)
vols
.
append
(
vol
)
ids
.
append
(
id
)
ob_vols
=
{
'vol'
:
vols
}
df
=
pd
.
DataFrame
(
data
=
ob_vols
,
index
=
ids
)
print
(
df
)
df
.
to_csv
(
'/path/to/volume/measurement-output/OB_volumes.csv'
,
header
=
True
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment