Skip to content

Commit

Permalink
Added: Added new deformation field for getting symmetrical spatially …
Browse files Browse the repository at this point in the history
…registered

         images for estimating laterality index.
Changed: Updated path of symmetrical deformation field.

Changed paths:
 M CHANGES.txt
 M cat_run_job1639.m
 M cat_vol_laterality_index.m
A  templates_MNI152NLin2009cAsym/y_MNI152NLin2009cAsym_to_MNI152NLin2009cSym.nii
  • Loading branch information
ChristianGaser committed Nov 13, 2023
1 parent 158a6e5 commit 1c37e73
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
12 changes: 12 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
------------------------------------------------------------------------
r2478 | gaser | 2023-11-13 15:41:36

Changed paths:
M CHANGES.txt
M cat_run_job1639.m
M cat_vol_laterality_index.m
A templates_MNI152NLin2009cAsym/y_MNI152NLin2009cAsym_to_MNI152NLin2009cSym.nii

Added: Added new deformation field for getting symmetrical spatially registered
images for estimating laterality index.
Changed: Updated path of symmetrical deformation field.
------------------------------------------------------------------------
r2477 | gaser | 2023-11-13 11:35:53

Changed paths:
Expand Down
1 change: 1 addition & 0 deletions cat_run_job1639.m
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ function cat_run_job1639(job,tpm,subj)
if (length(ff)>4 && strcmp(ff(1:5),'navg_')) || ...
(isfield(job,'useprior') && ~isempty(job.useprior)) || ...
(isfield(job.extopts,'new_release') && job.extopts.new_release)
fprintf('\n');
cat_io_cprintf('g8',' Use new longitudinal background setting. ');
% new minimal masking approach in longitudinal processing to avoid backgound peak erros and for future releases
Ymsk = cat_vol_morph( ~Ybg ,'dd',10,vx_vol) & ... % remove voxels far from head
Expand Down
36 changes: 21 additions & 15 deletions cat_vol_laterality_index.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ function cat_vol_laterality_index(P)
% Calculation of laterality index for images in MNI152NLin2009cAsym space
% LI = (L-R)/(R+L)
%
% We apply the deformation from MNI152NLin2009cAsym to the symmetrical template
% MNI152NLin2009cSym in order to obtain a symmetrical image, which then can be
% used to estimate laterality index.
% The result is indicated with a prepended 'LI_' in the dataname
% of the file.
% Please note that only the data of the left hemipshere is stored, since
Expand All @@ -24,41 +27,42 @@ function cat_vol_laterality_index(P)
P = spm_select(Inf,'image','Select images for LI estimation',{},pwd,'^w.*');
end

sym_template = '/Users/gaser/Dropbox/GitHub/cat12-templates-atlases/templates_external/y_MNI152NLin2009cAsym_to_MNI152NLin2009cSym.nii';
Vsym = spm_vol(sym_template);
Def_sym = fullfile(cat_get_defaults('extopts.pth_templates'),'y_MNI152NLin2009cAsym_to_MNI152NLin2009cSym.nii');
Vsym = spm_vol(Def_sym);

n = size(P,1);

cat_progress_bar('Init',n);

for i = 1:n
name = deblank(P(i,:));
V = spm_vol(name);
wvol = cat_vol_defs(struct('field1',{{sym_template}},'images',{{name}},'interp',5,'modulate',0));

% apply deformation to selected images
wvol = cat_vol_defs(struct('field1',{{Def_sym}},'images',{{name}},'interp',5,'modulate',0));

vol = wvol{1}{1};

% estimate new dimensions for left/right hemisphere
xdim = size(vol,1);
left_xdim = floor(xdim/2);
right_xdim = floor(xdim/2);

% consider off x-dimensions
% consider odd x-dimensions
if rem(xdim,2)
right_xdim = ceil(xdim/2) + 1;
left_xdim = ceil(xdim/2) + 1;
else
right_xdim = ceil(xdim/2);
left_xdim = ceil(xdim/2);
end

% flip values
left_data = vol(1:left_xdim,:,:);
right_data = flipud(vol(right_xdim:xdim,:,:)); % image should be flipped
left_data = flipud(vol(left_xdim:xdim,:,:)); % image should be flipped
right_data = vol(1:right_xdim,:,:);
mx = max(vol(:));

% estimate laterality index
LI = (right_data-left_data)./(left_data+right_data+eps);
LI = (left_data-right_data)./(left_data+right_data+eps);

% and exclude areas where intensity of tissue is quite low
LI((left_data+right_data)<0.01*mx) = 0;
% and exclude areas where intensity (i.e. of tissue) is quite low
LI(abs(left_data+right_data)<0.01*mx) = 0;

% rename dataname
[pth,nm,xt] = spm_fileparts(deblank(P(i,:)));
Expand All @@ -70,13 +74,15 @@ function cat_vol_laterality_index(P)
Vout.dim = size(LI);
Vout.dt(1) = 16;
Vout.pinfo(1) = 1;

% flipping is necessary
Vout.mat(1,:) = -Vout.mat(1,:);

Vout.descrip = 'Laterality index';
Vout.descrip = 'Laterality index (L-R)/(R+L)';

spm_write_vol(Vout,LI);
fprintf('Save LI in %s\n',flipped_name);
cat_progress_bar('Set',i);
cat_progress_bar('Set',i);
end

cat_progress_bar('Clear');
Binary file not shown.

0 comments on commit 1c37e73

Please sign in to comment.