Attachment 'brainsync.py'
Download 1 import scipy as sp
2 """
3 BrainSync: An Orthogonal Transform for Syncronize the subject fMRI data to the reference fMRI data
4 Authors: Anand A Joshi, Minqi Chong, Jian Li, Richard M. Leahy
5 Based on
6 AA Joshi, M Chong, RM Leahy, BrainSync: An Orthogonal Transformation for Synchronization of fMRI Data Across Subjects, Proc. MICCAI 2017.
7
8
9 """
10
11 def normalizeData(pre_signal):
12 """
13 normed_signal, mean_vector, std_vector = normalizeData(pre_signal)
14 This function normalizes the input signal to have 0 mean and unit
15 variance in time.
16 pre_signal: Time x Original Vertices data
17 normed_signal: Normalized (Time x Vertices) signal
18 mean_vector: Vertices x 1 mean for each time series
19 std_vector : Vertices x 1 std dev for each time series
20 """
21 if sp.any(sp.isnan(pre_signal)):
22 print('there are NaNs in the data matrix, synchronization\
23 may not work')
24
25 pre_signal[sp.isnan(pre_signal)] = 0
26 mean_vector = sp.mean(pre_signal, axis=0, keepdims=True)
27 normed_signal = pre_signal - mean_vector
28 std_vector = sp.std(normed_signal, axis=0, keepdims=True)
29 std_vector[std_vector == 0] = 1
30 normed_signal = normed_signal / std_vector
31
32 return normed_signal, mean_vector, std_vector
33
34
35 def brainSync(X, Y):
36 """
37 Input:
38 X - Time series of the reference data (Time x Vertex)
39 Y - Time series of the subject data (Time x Vertex)
40
41 Output:
42 Y2 - Synced subject data with respect to reference data (Time x Vertex)
43 R - The orthogonal rotation matrix (Time x Time)
44
45 Please cite the following publication:
46 AA Joshi, M Chong, RM Leahy, BrainSync: An Orthogonal Transformation
47 for Synchronization of fMRI Data Across Subjects, Proc. MICCAI 2017,
48 in press.
49 """
50 if X.shape[0] > X.shape[1]:
51 print('The input is possibly transposed. Please check to make sure \
52 that the input is time x vertices!')
53
54 C = sp.dot(X, Y.T)
55 U, _, V = sp.linalg.svd(C)
56 R = sp.dot(U, V)
57 Y2 = sp.dot(R, Y)
58 return Y2, R
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.