Skip to content

Commit 9fa8352

Browse files
committed
Add function to compute volume center
1 parent f6772b2 commit 9fa8352

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

CPAC/generate_motion_statistics/generate_motion_statistics.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,29 @@ def calculate_FD_J(in_file, motion_correct_tool='3dvolreg', center=None):
390390
return out_file
391391

392392

393+
def find_volume_center(img_file):
394+
"""
395+
Find the center of mass of a Nifti image volume
396+
397+
Parameters
398+
----------
399+
img_file : string (nifti file)
400+
path to nifti volume image
401+
402+
Returns
403+
-------
404+
center : ndarray
405+
volume center of mass vector
406+
"""
407+
img = nb.load(img_file)
408+
dim = np.array(img.header["dim"][1:4])
409+
pixdim = np.array(img.header["pixdim"][1:4])
410+
# Calculation follows MCFLIRT
411+
# https://github.com/fithisux/FSL/blob/7aa2932949129f5c61af912ea677d4dbda843895/src/mcflirt/mcflirt.cc#L479
412+
center = 0.5 * (dim - 1) * pixdim
413+
return center
414+
415+
393416
def gen_motion_parameters(subject_id, scan_id, movement_parameters,
394417
max_displacement, motion_correct_tool):
395418
"""

0 commit comments

Comments
 (0)