Skip to content

Commit

Permalink
1) Fixed: Corrections for T2/PD contrasts in cat_main and cat_main_gi…
Browse files Browse the repository at this point in the history
…ntnorm.

2) Fixed:     Corrected internal call of vol2surf.
3) Fixed:     Corrected bug in cat_vol_resize in case of minimal reduction by
              averaging on only 2 values.
4) Fixed:     Corrected bug in cat_surf_display and cat_main_reportfig to
              show cerebellar surfaces.
5) Fixed:     Deactivated T1 template mapping for (cerebellar) surface
              reconstruction due to incorrect application of the deformation
              in cat_main1639 (was already done in cat_main).
6) Changed:   Introduced cat_io_contains in cat_main_reportfig.
7) Comment:   Extended documentation in cat_vol_sample and cat_main1639.
8) Fixed:     Corrected bug in cerebellar reconstruction in cat_surf_createCS2.

Changed paths:
 M CHANGES.txt
 M cat_main1639.m
 M cat_main_reportfig.m
 M cat_surf_createCS2.m
 M cat_surf_display.m
 M cat_vol_resize.m
 M cat_vol_sample.m
  • Loading branch information
robdahn committed Jan 24, 2024
1 parent 45e1926 commit 7e2a659
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
25 changes: 25 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
------------------------------------------------------------------------
r2528 | rdahnke | 2024-01-24 17:01:43

Changed paths:
M CHANGES.txt
M cat_main1639.m
M cat_main_reportfig.m
M cat_surf_createCS2.m
M cat_surf_display.m
M cat_vol_resize.m
M cat_vol_sample.m

1) Fixed: Corrections for T2/PD contrasts in cat_main and cat_main_gintnorm.
2) Fixed: Corrected internal call of vol2surf.
3) Fixed: Corrected bug in cat_vol_resize in case of minimal reduction by
averaging on only 2 values.
4) Fixed: Corrected bug in cat_surf_display and cat_main_reportfig to
show cerebellar surfaces.
5) Fixed: Deactivated T1 template mapping for (cerebellar) surface
reconstruction due to incorrect application of the deformation
in cat_main1639 (was already done in cat_main).
6) Changed: Introduced cat_io_contains in cat_main_reportfig.
7) Comment: Extended documentation in cat_vol_sample and cat_main1639.
8) Fixed: Corrected bug in cerebellar reconstruction in cat_surf_createCS2.

------------------------------------------------------------------------
r2520 | gaser | 2024-01-16 10:36:41

Expand Down
10 changes: 7 additions & 3 deletions cat_main1639.m
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,12 @@
surf = unique(surf);
end
%% RD202107: Load Shooting template to correct severe defects in the
% parahippocampla gyrus. Previously also used to stabilize
% the cerebellum but it introduce some Shooting problems.
if job.extopts.close_parahipp %any( ~cellfun('isempty', strfind(surf,'cb') )) % ... I want to avoid this if possible - it also seem to be worse to use it
% parahippocampla gyrus. Previously also used to stabilize
% the cerebellum but it introduce some Shooting problems.
% RD202401: There is a bug and the T1-template is not in the same space
% (eg. HR075). Maybe because the Yy is defined for the
% TPM but not the T1-template properties.
if 0 % job.extopts.close_parahipp %any( ~cellfun('isempty', strfind(surf,'cb') )) % ... I want to avoid this if possible - it also seem to be worse to use it
VT1 = spm_vol(cat_get_defaults('extopts.shootingT1')); VT1 = VT1{1};
fac = abs(tpm.V(1).mat(1)) / abs(VT1.mat(1));
YT = single(spm_sample_vol(VT1,double(smooth3(Yy(:,:,:,1))*fac),double(smooth3(Yy(:,:,:,2))*fac),double(smooth3(Yy(:,:,:,3))*fac),2));
Expand Down Expand Up @@ -804,6 +807,7 @@
qa.subjectmeasures.EC_abs = NaN;
qa.subjectmeasures.defect_size = NaN;
else
%%
[Yth1, S, Psurf, qa.subjectmeasures.EC_abs, qa.subjectmeasures.defect_size, qa.createCS] = ...
cat_surf_createCS2(VT,VT0,Ymix,Yl1,YMF,YT,struct('trans',trans,'reduce_mesh',job.extopts.reduce_mesh,... required for Ypp output
'vdist',job.extopts.vdist,'outputpp',job.output.pp,'surf_measures',job.output.surf_measures, ...
Expand Down
25 changes: 13 additions & 12 deletions cat_main_reportfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
% - missing information of interesting lower and median regions
sidehist = 1; %job.extopts.expertgui>1;
try
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'lh.')) ,1, 'first');
id1 = find( cat_io_contains({Psurf(:).Pcentral},'lh.') ,1, 'first');
spm_figure('Focus','Graphics');
% this is strange but a 3:4 box property results in a larger brain scaling
hCS = subplot('Position',[0.52 0.037*(~sidehist) 0.42 0.31+0.02*sidehist],'visible','off');
Expand Down Expand Up @@ -1394,12 +1394,12 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
%%
for i = 1:numel(Psurf)
if i == 1
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'lh.')) ,1, 'first');
id1 = find( cat_io_contains({Psurf(:).Pcentral},'lh.') ,1, 'first');
CS = gifti( Psurf(id1).Pcentral );
T = cat_io_FreeSurfer('read_surf_data',Psurf(id1).Pthick );
CS.cdata = T;
else
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'rh.')) ,1, 'first');
id1 = find( cat_io_contains({Psurf(:).Pcentral},'rh.') ,1, 'first');
S = gifti( Psurf(id1).Pcentral );
T = cat_io_FreeSurfer('read_surf_data',Psurf(id1).Pthick );
CS.faces = [ CS.faces; S.faces + size(CS.vertices,1) ];
Expand Down Expand Up @@ -1462,8 +1462,8 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
end
elseif job.extopts.report.type >= 2
spm_figure('Focus','Graphics');
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'lh.')) ,1, 'first');
id2 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'rh.')) ,1, 'first');
id1 = find( cat_io_contains({Psurf(:).Pcentral},'lh.') ,1, 'first');
id2 = find( cat_io_contains({Psurf(:).Pcentral},'rh.') ,1, 'first');
% this is strange but a 3:4 box property result in a larger brain scaling
hCS{1} = subplot('Position',[0.34 0.07 0.32 0.27],'Parent',fg,'visible','off'); PCS{1} = Psurf(id1).Pthick; sview{1} = 't';
hCS{2} = subplot('Position',[0.02 0.18 0.30 0.17],'Parent',fg,'visible','off'); PCS{2} = Psurf(id1).Pthick; sview{2} = 'l';
Expand All @@ -1489,16 +1489,17 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
boxwidth = diff(srange)/30 / 2; % 0.1;
end
%% hrange = srange(1) + boxwidth/2:boxwidth:srange(2);
if job.output.surface > 10, addcb = 1; else, addcb = 0; end
if strcmpi(renderer,'opengl')
try
i=1; hSD{i} = cat_surf_display(struct('data',PCS{i},'readsurf',0,'expert',2,...
'multisurf',1,'view',sview{i},'menu',0,'parent',hCS{i},'verb',0,'caxis',srange,'imgprint',struct('do',0)));
'multisurf',1 + 2*addcb,'view',sview{i},'menu',0,'parent',hCS{i},'verb',0,'caxis',srange,'imgprint',struct('do',0)));
end

for i = 2:numel(hCS)
try
hSD{i} = cat_surf_display(struct('data',PCS{i},'readsurf',0,'expert',2,...
'multisurf',0,'view',sview{i},'menu',0,'parent',hCS{i},'verb',0,'caxis',srange,'imgprint',struct('do',0)));
'multisurf',0 + 3*addcb,'view',sview{i},'menu',0,'parent',hCS{i},'verb',0,'caxis',srange,'imgprint',struct('do',0)));
end
end

Expand All @@ -1524,13 +1525,13 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
% just the first draft
for i = 1:numel(Psurf)
if i == 1
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'lh.')) ,1, 'first');
id1 = find( cat_io_contains({Psurf(:).Pcentral},'lh.') ,1, 'first');
CS = gifti( Psurf(id1).Pcentral );
T = cat_io_FreeSurfer('read_surf_data',Psurf(id1).Pthick );
CS.cdata = T;
CSl = CS;
else
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},'rh.')) ,1, 'first');
id1 = find( cat_io_contains({Psurf(:).Pcentral},'rh.') ,1, 'first');
S = gifti( Psurf(id1).Pcentral );
T = cat_io_FreeSurfer('read_surf_data',Psurf(id1).Pthick );
CS.faces = [ CS.faces; S.faces + size(CS.vertices,1) ];
Expand All @@ -1549,8 +1550,8 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
% resolution but the thickness data mapping is not working
% yet ...
side = {'lh.','rh.'};
for si=1:2
id1 = find( ~cellfun('isempty',strfind({Psurf(:).Pcentral},side{si})) ,1, 'first');
for si = 1:numel(side)
id1 = find( cat_io_contains({Psurf(:).Pcentral},side{si}) ,1, 'first');
% quaranty 1 mm mesh resolution
Pcentral = sprintf('%s.gii',tempname);
CSo = gifti(Psurf(id1).Pcentral);
Expand All @@ -1570,7 +1571,7 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)

%%
imat = spm_imatrix(res.Affine); Rigid = spm_matrix([imat(1:6) ones(1,3)*mean(imat(7:9)) 0 0 0]); clear imat;
V = (Rigid * ([CS.vertices, ones(size(CS.vertices,1),1)])' )'; V(:,4) = []; CS.vertices = V;
V = (Rigid * ([CS.vertices, ones(size(CS.vertices ,1),1)])' )'; V(:,4) = []; CS.vertices = V;
V = (Rigid * ([CSl.vertices, ones(size(CSl.vertices,1),1)])' )'; V(:,4) = []; CSl.vertices = V;
V = (Rigid * ([CSr.vertices, ones(size(CSr.vertices,1),1)])' )'; V(:,4) = []; CSr.vertices = V;

Expand Down
4 changes: 2 additions & 2 deletions cat_surf_createCS2.m
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@
%% thickness depending cortical scaling - this seems to work but need further tests (RD201911)
% RD202103 ... this changes a lot !
Yth1i = cat_vol_localstat(Yth1i,Yth1i>0,2,2);
Yts = cat_vol_approx(Yth1i,2);
Yts = cat_vol_approx(Yth1i);
Yts = 1 + max(-0.5,min(0.5,(Yts - mean(Yth1i(:))) / (2 * mean(Yth1i(:))) ));
if exist('mask_parahipp_smoothed','var')
Yts = Yts .* (1-mask_parahipp_smoothed) + mask_parahipp_smoothed; % no thickness adaptation in the hippocampus!
Expand Down Expand Up @@ -2108,7 +2108,7 @@ function saveSurf(CS,P)
%% bias-correction based
% WM
Ycsfd = cat_vbdist(single(Ymf<1.8),Ymf>1,vx_vol);
Ymsk = ((cat_vol_morph(NS(Ya,LAB.CB),'e',3) | Ymf) & ( (Ym-Ydiv).*(Ytemplate/3-Ydivt) )>2/3 ) | ...
Ymsk = ((cat_vol_morph(NS(Ya,LAB.CB),'e',3) | Ymf) & ( (Ym-Ydiv).*min(1,Ytemplate/3-Ydivt) )>2/3 ) | ...
(NS(Ya,LAB.PH) & ( Ymf>2.2 | (Ymf>2 & Ydiv<-0.01) ) ) | ... % hippocampal gyri
(NS(Ya,LAB.CT) & ( Ymf>2.2 | (Ymf>2 & Ydiv<-0.01 & ...
Ycsfd>cat_stat_nanmean(Ycsfd(Ycsfd(:)>0 & Ycsfd(:)<100)) )*1.0) ); % distant gyri and sulci in the cerebrum
Expand Down
4 changes: 2 additions & 2 deletions cat_surf_display.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@
if job.multisurf==3
Pmesh = [ ...
cat_surf_rename(sinfo(i).Pmesh,'side','lh') cat_surf_rename(sinfo(i).Pmesh,'side','rh') ...
cat_surf_rename(sinfo(i).Pmesh,'side','lc') cat_surf_rename(sinfo(i).Pmesh,'side','rc')];
cat_surf_rename(sinfo(i).Pmesh,'side','cb') ];
Pdata = [ ...
cat_surf_rename(sinfo(i).Pdata,'side','lh') cat_surf_rename(sinfo(i).Pdata,'side','rh') ...
cat_surf_rename(sinfo(i).Pdata,'side','lc') cat_surf_rename(sinfo(i).Pdata,'side','rc')];
cat_surf_rename(sinfo(i).Pdata,'side','cb') ];
elseif job.multisurf==2
if strcmp('h',sinfo(i).side(2)), oside = [sinfo(i).side(1) 'c']; else, oside = [sinfo(i).side(1) 'h']; end
Pmesh = [sinfo(i).Pmesh cat_surf_rename(sinfo(i).Pmesh,'side',oside)];
Expand Down
2 changes: 1 addition & 1 deletion cat_vol_resize.m
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
% irgnore values with too small input
switch interp
case {'meanm','min','max','stdm','median'}
varargout{i}( counter(:) <= minvoxcount | isinf( varargout{i}(:) ) | isnan(varargout{i}(:)) ) = 0;
varargout{i}( counter(:) < minvoxcount | isinf( varargout{i}(:) ) | isnan(varargout{i}(:)) ) = 0;
end

%% set upt resT variable for dereducev case
Expand Down
5 changes: 5 additions & 0 deletions cat_vol_sample.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
% ______________________________________________________________________
% $Id$

% RD202401: The definition could be improved to resample images with
% stronger variing properties correctly, e.g. the T1 template
% before the surface reconstruction in the cat_main[1639]
% pipelines.

if ~exist('hold','var'), hold = 1; end

if isstruct(PT), VT = PT; elseif ~isempty(PT), VT = spm_vol(PT); else, VT = []; end
Expand Down

0 comments on commit 7e2a659

Please sign in to comment.