1 | function corrmap = fmri_corr(data,seed) |
---|

2 | |
---|

3 | corrmap = []; |
---|

4 | |
---|

5 | if ischar(data) |
---|

6 | data=aedes_data_read(data); |
---|

7 | data = data.FTDATA; |
---|

8 | elseif isstruct(data) |
---|

9 | data=data.FTDATA; |
---|

10 | end |
---|

11 | |
---|

12 | % Get mean time-series from seed ROIs |
---|

13 | seed_struct = l_Roi2seed(data,seed); |
---|

14 | |
---|

15 | |
---|

16 | % Calculate Pearson correlation coefficients ------------- |
---|

17 | data_sz = ones(1,4); |
---|

18 | data_sz(1:ndims(data)) = size(data); |
---|

19 | |
---|

20 | for kk = 1:length(seed_struct) |
---|

21 | |
---|

22 | % Allocate space for ccc |
---|

23 | ccc = zeros(data_sz(1:3)); |
---|

24 | |
---|

25 | T = length(seed_struct(kk).data); |
---|

26 | std_seed = std(seed_struct(kk).data,1); |
---|

27 | norm_seed = seed_struct(kk).data-mean(seed_struct(kk).data); |
---|

28 | seed_plane = reshape(reshape(repmat(norm_seed,... |
---|

29 | [data_sz(1),data_sz(2)]),data_sz(1)*T,[]).',... |
---|

30 | data_sz(1),data_sz(2),[]); |
---|

31 | |
---|

32 | % Loop over in-plane slices |
---|

33 | for ii=1:data_sz(3) |
---|

34 | tmp_data = double(squeeze(data(:,:,ii,:))); |
---|

35 | |
---|

36 | std_data = std(tmp_data,1,3); |
---|

37 | |
---|

38 | ccc(:,:,ii) = ((1/T)*sum(seed_plane.*tmp_data,3))./(std_data.*std_seed); |
---|

39 | end |
---|

40 | |
---|

41 | % Make sure that there are no Infs or nans ... |
---|

42 | ccc(find(isnan(ccc))) = 0; |
---|

43 | ccc(find(isinf(ccc))) = 0; |
---|

44 | |
---|

45 | % Fisher's z-transform to make values normally distributed |
---|

46 | zf = ccc; |
---|

47 | zf = 0.5*log((1+ccc)./(1-ccc)); |
---|

48 | |
---|

49 | % Calculate Z-scores |
---|

50 | zscore = zf./(1/sqrt(T-3)); |
---|

51 | |
---|

52 | % Construct output structure |
---|

53 | corrmap(kk).ccc = ccc; |
---|

54 | corrmap(kk).zf = zf; |
---|

55 | corrmap(kk).zscore = zscore; |
---|

56 | corrmap(kk).label = seed_struct(kk).label; |
---|

57 | end |
---|

58 | |
---|

59 | % Subfunctions ----------------------------------- |
---|

60 | function seed_struct = l_Roi2seed(data,ROI) |
---|

61 | % Thus subfunction extracts mean seed time-series from ROI voxels |
---|

62 | % |
---|

63 | |
---|

64 | seed_struct = []; |
---|

65 | |
---|

66 | if isstruct(ROI) |
---|

67 | for ii=1:length(ROI) |
---|

68 | ind = repmat(ROI(ii).voxels{1}(:,:,:,1),[1 1 1 size(data,4)]); |
---|

69 | seed_struct(ii).data = mean(reshape(double(data(ind)),[],size(data,4))); |
---|

70 | seed_struct(ii).label = ROI(ii).label; |
---|

71 | end |
---|

72 | else |
---|

73 | tmp = ROI(:).'; |
---|

74 | seed_struct(1).data = double(tmp); |
---|

75 | seed_struct(1).label = 'custom seed'; |
---|

76 | end |
---|

77 | |
---|

78 | |
---|

79 | |
---|