def get_motion_level(directory,translation_threshold=2.5,rotation_threshold=2.5):
'''Roughly classify the amount of motion per slice for calculating likelihood of signal dropouts - 1 = severe motion, 2 = moderate motion'''
motion_path = os.path.join(directory,'motion')
motion = np.loadtxt(motion_path)
max_motion = np.max(motion[:,1:],axis=0)
min_motion = np.min(motion[:,1:],axis=0)
diff_motion = np.abs(max_motion-min_motion)
diff_motion[:3] = diff_motion[:3]*1000
diff_motion[3:] = np.rad2deg(diff_motion[3:])
if np.any( diff_motion[:3] > translation_threshold):
return 1
elif np.any(diff_motion[3:] > rotation_threshold):
return 1
elif np.any( diff_motion[:3] > 1):
return 2
elif np.any(diff_motion[3:] > 1):
return 2
else:
return 0
评论列表
文章目录