相关性分析代码片段

ldcca_tms = img_To_4D_array('C:\Users\Administrator\Desktop\contrast\2014-05-20-17-10.img');
spm_tms = img_To_4D_array('C:\Users\Administrator\Desktop\contrast\no_phycaa.img');

% x = size(spm_tms,1);
% y = size(spm_tms,2);
% z = size(spm_tms,3);
% 
% %spm_tms_1d = reshape(spm_tms ,[1,x*y*z] );
% 
% 
% x = size(ldcca_tms,1);
% y = size(ldcca_tms,2);
% z = size(ldcca_tms,3);
% 
% % ldcca_tms_1d = reshape( ldcca_tms , [1,x*y*z] );


mask_ldcca_tms = ldcca_tms > 0;

inv_mask_ldcca_tms = ~mask_ldcca_tms;

mask_spm_tms = spm_tms > 0;

inv_mask_spm_tms = ~mask_spm_tms;


%% 先提取出被去噪去除的点的时间过程  实验结果,去除了435个点,

% left_spm_tms = spm_tms(inv_mask_ldcca_tms);

tmp_spm = spm_tms .* inv_mask_ldcca_tms;


%>>这是最后的模板
mask_big_left_spm_tms = tmp_spm>0;

% big_left_spm_tms = left_spm_tms(left_spm_tms>0);


% aa = size(big_left_spm_tms)


%% 利用我们的去噪算法,得到的新的点,一个点都没有增加

% left_ldcca_tms = ldcca_tms(ldcca_tms);

tmp_ldcca = ldcca_tms .* inv_mask_spm_tms;

%>>这是最后的模板
mask_big_left_ldcca_tms = tmp_ldcca > 0; 

 tmp_ldcca_data = tmp_ldcca>0;
 
 tmp_ldcca_data_sum = size( tmp_ldcca(tmp_ldcca_data))

% big_left_ldcca_tms = left_ldcca_tms( left_ldcca_tms>0 );

% bb = size(big_left_ldcca_tms)



%% 提取被去除的点的时间过程
%--brain functional 4d data

datacell_4d   = load_untouch_nii('C:\Users\Administrator\Desktop\workspace\phycaa_plus_2104_03_27\func_4d.nii'); 


ldim = size(datacell_4d.img);


fullMsk = repmat( mask_big_left_spm_tms, [1,1,1,ldim(4)] );



 nii     = V; % copy nifti struct
 nii.img = fullMsk; % replace volume
                
%nii.hdr.dime.dim(5) = size(TMPVOL,4); % adjust for #timepoints
          
save_untouch_nii(nii,'mask_left_spm_tms_2d.nii'); 











left_spm_tms_2d = reshape( datacell_4d.img(fullMsk>0), [], ldim(4) );

inv_fullMsk =  repmat( mask_spm_tms.*(~mask_big_left_spm_tms), [1,1,1,ldim(4)] );
inv_left_spm_tms_2d = reshape( datacell_4d.img(inv_fullMsk>0), [], ldim(4) );



 nii     = V; % copy nifti struct
 nii.img = inv_fullMsk; % replace volume
                
%nii.hdr.dime.dim(5) = size(TMPVOL,4); % adjust for #timepoints
          
save_untouch_nii(nii,'inv_left_spm_tms_2d.nii'); 


%% 计算相关系数 
reference_stimulus =[
    0 0 0 0 0 0 0 0 0 0 ...
    1 1 1 1 1 1 1 1 1 1 ...
    0 0 0 0 0 0 0 0 0 0 ...
    1 1 1 1 1 1 1 1 1 1 ...
    0 0 0 0 0 0 0 0 0 0 ...
    1 1 1 1 1 1 1 1 1 1 ...
    0 0 0 0 0 0 0 0 0 0
];

corr_left_spms=[];
intensitivity_spms=[];

for i = 1:size(left_spm_tms_2d,1)
   
%     corr_left_spms{i} = corrcoef(reference_stimulus' , left_spm_tms_2d(i,:)');
    corr_left_spms(i)= corr2(reference_stimulus' , left_spm_tms_2d(i,:)');
    intensitivity_spms(i)=mean( left_spm_tms_2d(i,:) );
end

mean_corr = mean(corr_left_spms);
median_corr = median(corr_left_spms);
min_corr = min(corr_left_spms);

max_corr = max(corr_left_spms);


%max_mask = ;






mean_intensitivity = mean(intensitivity_spms);
median_intensitivity = median(intensitivity_spms);
min_intensitivity = min(intensitivity_spms);


inv_corr_left_spms=[];


for i = 1:size(left_spm_tms_2d,1)
   
%     corr_left_spms{i} = corrcoef(reference_stimulus' , left_spm_tms_2d(i,:)');
    inv_corr_left_spms(i)= corr2(reference_stimulus' , inv_left_spm_tms_2d(i,:)');
    inv_intensitivity_spms(i)=mean( inv_left_spm_tms_2d(i,:) );
end

inv_mean_corr = mean(inv_corr_left_spms);
inv_median_corr = median(inv_corr_left_spms);
inv_min_corr = min(inv_corr_left_spms);

inv_max_corr = max(inv_corr_left_spms);


inv_mean_intensitivity = mean(inv_intensitivity_spms);
inv_median_intensitivity = median(inv_intensitivity_spms);
inv_min_intensitivity = min(inv_intensitivity_spms);


big_than_inv_min_corr = sum( double( corr_left_spms >inv_min_corr ));

  

posted @ 2014-06-19 09:27  二郎那个三郎  阅读(482)  评论(0编辑  收藏  举报