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

2 | |
---|

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

4 | |
---|

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

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

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

8 | end |
---|

9 | |
---|

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

11 | |
---|

12 | |
---|

13 | |
---|

14 | % Calculate Pearson correlation coefficients ------------- |
---|

15 | |
---|

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

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

18 | |
---|

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

20 | |
---|

21 | % Allocate space for ccc |
---|

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

23 | |
---|

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

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

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

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

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

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

30 | |
---|

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

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

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

34 | |
---|

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

36 | |
---|

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

38 | end |
---|

39 | |
---|

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

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

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

43 | |
---|

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

45 | zf = ccc; |
---|

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

47 | |
---|

48 | % Calculate Z-scores |
---|

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

50 | |
---|

51 | % Construct output structure |
---|

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

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

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

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

56 | end |
---|

57 | |
---|

58 | % Subfunctions ----------------------------------- |
---|

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

60 | |
---|

61 | seed_struct = []; |
---|

62 | |
---|

63 | if isstruct(ROI) |
---|

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

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

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

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

68 | end |
---|

69 | else |
---|

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

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

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

73 | end |
---|

74 | |
---|

75 | |
---|

76 | |
---|