Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UTILS] New utils function to compute voxel size for a volume #101

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions narps_open/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,27 @@ def fmriprep_data_template() -> dict:
)

return {"func_preproc": func_preproc, "confounds_file": confounds_file}

def get_vox_dims(volume : list) -> list:
'''
Function that gives the voxel dimension of an image.
Not used here but if we use it, modify the connection to :
(?, normalize_func, [('?', 'apply_to_files'),
(('?', get_vox_dims),
'write_voxel_sizes')])

Args:
volume: list | str
List of str or str that represent a path to a Nifti image.

Returns:
list:
size of the voxels in the volume or in the first volume of the list.
'''
import nibabel as nb
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
hdr = nii.header
voxdims = hdr.get_zooms()
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]
Loading