Skip to content

Commit

Permalink
Merge pull request #12 from ChristianGaser/9-cleanup
Browse files Browse the repository at this point in the history
9 cleanup
  • Loading branch information
robdahn authored Dec 9, 2023
2 parents d094548 + f41331b commit 5914c08
Show file tree
Hide file tree
Showing 21 changed files with 964 additions and 2,601 deletions.
8 changes: 0 additions & 8 deletions cat_conf_opts.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
};
tpm.num = [1 1];
tpm.def = @(val)cat_get_defaults('opts.tpm', val{:});
if expert>1
tpm.help = [tpm.help
{
'In case of multiple TPMs, the original image is affine registrated to each TPM and a kmeans algorithm is used to fit 3 classes. The best two images with the lowest standard deviations are combined to a new less biased TPM. The TPMs must include the same classes in MNI space!'
''
}];
tpm.num = [1 inf];
end


% ngaus:
Expand Down
2 changes: 1 addition & 1 deletion cat_main.m
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
if job.extopts.LASstr>1 || job.extopts.inv_weighting
[Ymi,Ymt,Ycls] = cat_main_LASs(Ysrc,Ycls,Ym,Yb,Yy,Tth,res,vx_vol,extoptsLAS2); % use Yclsi after cat_vol_partvol
else
[Ymi,Ymt,Ycls] = cat_main_LAS2(Ysrc,Ycls,Ym,Yb,Yy,T3th,res,vx_vol,job.extopts,Tth);
[Ymi,Ymt,Ycls] = cat_main_LAS(Ysrc,Ycls,Ym,Yb,Yy,T3th,res,vx_vol,job.extopts,Tth);
end
clear Ymt; % use original global scaled ...
stime2 = clock; % not really correct but better than before
Expand Down
2 changes: 1 addition & 1 deletion cat_main1639.m
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
if job.extopts.LASstr>1
[Ymi,Ym,Ycls] = cat_main_LASs(Ysrc,Ycls,Ym,Yb,Yy,Tth,res,vx_vol,extoptsLAS2); % use Yclsi after cat_vol_partvol
else
[Ymi,Ym,Ycls] = cat_main_LAS2(Ysrc,Ycls,Ym,Yb,Yy,T3th,res,vx_vol,job.extopts,Tth);
[Ymi,Ym,Ycls] = cat_main_LAS(Ysrc,Ycls,Ym,Yb,Yy,T3th,res,vx_vol,job.extopts,Tth);
end
stime2 = clock; % not really correct but better than before

Expand Down
1,040 changes: 681 additions & 359 deletions cat_main_LAS.m

Large diffs are not rendered by default.

902 changes: 0 additions & 902 deletions cat_main_LAS2.m

This file was deleted.

86 changes: 33 additions & 53 deletions cat_main_LASs.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
else wmtht = 1;
end


%% tissue thresholds
% you need to know which are the extrem classes to define there PVE
[gmm,gms,gmn] = cat_stat_kmeans(Ysrc(cat_vol_morph(Ygm & Ycls{1}>128,'e')),3); % we need 3 GM types to include GM/WM and GM/CSF PVE voxels
Expand All @@ -288,56 +289,35 @@
TSmx = (TSth == max(TSth)) - (TSth == min(TSth));
TSth = TSth + TSmx .* [mean(gms(wmn>0.5)) mean(wms(wmn>0.5)) mean(cms(cmn>0.5))];

%%
if 1
Ysrcm = cat_vol_localstat(Ysrc .* Ywm,Ywm,1,wmtht);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,2,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0) + std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);
Ysrca = Ysrcm;
Ysrcmw = cat_vol_approx(Ysrcm,'nh',vx_vol,4); Ysrcmw = cat_vol_smooth3X(Ysrcmw,2);

Ysrcm = cat_vol_localstat(Ysrc ./ TSth(1) .* TSth(2) .* (Ycls{1}>4),(Ygm & Ycls{1}>4),1,1);%Ygm &
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,4,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrca = Ysrca + Ysrcm;
Ysrcmg = cat_vol_approx(Ysrcm,'nh',vx_vol,4); Ysrcmg = cat_vol_smooth3X(Ysrcmg,LASfs);

Ysrcm = cat_vol_localstat(Ysrc ./ TSth(3) .* TSth(2) .* (Ycm & Ycls{3}>4),(Ycm & Ycls{3}>4),1,1);
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,2,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrca = Ysrca + Ysrcm;
Ysrcmc = cat_vol_approx(Ysrcm,'nh',vx_vol,4); Ysrcmc = cat_vol_smooth3X(Ysrcmc,LASfs);

Ysrcma = cat_vol_approx(Ysrca,'nh',vx_vol,2); Ysrcma = cat_vol_smooth3X(Ysrcma,LASfs);
Ysrcs = cat_vol_localstat(Ysrcma,Ysrcma>0,2,4);
Ysrcma(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;

Yi = cat_vol_approx(Ysrcma,'nh',vx_vol,2); Yi = cat_vol_smooth3X(Yi,2);
Ylab{2} = Yi;
else

Ysrcm = cat_vol_localstat(Ysrc .* Ywm,Ywm,1,wmtht) + ...
cat_vol_localstat(Ysrc ./ TSth(1) .* TSth(2) .* (Ygm & Ycls{1}>128),(Ygm & Ycls{1}>128),1,1) + ...
cat_vol_localstat(Ysrc ./ TSth(3) .* TSth(2) .* (Ycm & Ycls{3}>240),(Ycm & Ycls{3}>240),1,1);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,2,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrcm2 = Ysrcm;
YM = cat_vol_morph(Ysrcm>0,'d') & Yp0>1 & Ysrcm==0; Ysrcm2(YM) = Ysrc(YM);
Ysrcm2 = cat_vol_localstat(Ysrcm2,Ysrcm2>0,2,wmtht); Ysrcm(YM) = Ysrcm2(YM);
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);

% major correction outside the brain
[Yi ,resT2] = cat_vol_resize(Ysrcm,'reduceV',vx_vol,mres,32,'meanm'); % maximum reduction for the WM
if ~debug, clear Ysrcm Ydiv; end
Yi(smooth3(Yi>0)<0.5)=0; Yi(smooth3(Yi>0)<0.5)=0;

% Yi(Yi==0 & Ygi>0)=Ygi(Yi==0 & Ygi>0); if ~debug, clear Ygi; end
Yi = cat_vol_approx(Yi,'nh',resT2.vx_volr,4); Yi = cat_vol_smooth3X(Yi,LASfs);
Ylab{2} = max(eps,cat_vol_resize(Yi,'dereduceV',resT2));
end

%% WM
Ysrcm = cat_vol_localstat(Ysrc .* Ywm,Ywm,1,wmtht);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,2,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0) + std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);
Ysrca = Ysrcm;
Ysrcmw = cat_vol_approx(Ysrcm,'nh',vx_vol,4); Ysrcmw = cat_vol_smooth3X(Ysrcmw,2);

Ysrcm = cat_vol_localstat(Ysrc ./ TSth(1) .* TSth(2) .* (Ycls{1}>4),(Ygm & Ycls{1}>4),1,1);%Ygm &
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,4,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrca = Ysrca + Ysrcm;
Ysrcmg = cat_vol_approx(Ysrcm,'nh',vx_vol,4); Ysrcmg = cat_vol_smooth3X(Ysrcmg,LASfs);

Ysrcm = cat_vol_localstat(Ysrc ./ TSth(3) .* TSth(2) .* (Ycm & Ycls{3}>4),(Ycm & Ycls{3}>4),1,1);
Ysrcm = cat_vol_noPVE(Ysrcm,res.isMP2RAGE,vx_vol,2);
Ysrcs = cat_vol_localstat(Ysrcm,Ysrcm>0,2,4);
Ysrcm(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;
Ysrca = Ysrca + Ysrcm;
Ysrcmc = cat_vol_approx(Ysrcm,'nh',vx_vol,4); Ysrcmc = cat_vol_smooth3X(Ysrcmc,LASfs);

Ysrcma = cat_vol_approx(Ysrca,'nh',vx_vol,2); Ysrcma = cat_vol_smooth3X(Ysrcma,LASfs);
Ysrcs = cat_vol_localstat(Ysrcma,Ysrcma>0,2,4);
Ysrcma(Ysrcs>mean(Ysrcs(Ysrcs(:)>0)+std(Ysrcs(Ysrcs(:)>0) ))) = 0;

Yi = cat_vol_approx(Ysrcma,'nh',vx_vol,2); Yi = cat_vol_smooth3X(Yi,2);
Ylab{2} = Yi;
if ~debug, clear Yi; end


Expand Down Expand Up @@ -403,6 +383,7 @@
end
clear Ynba Yca;


%% back to original resolution
if any(resTb.vx_vol ~= resTb.vx_volr)
Ysrc = Ysrco; clear Ysrco;
Expand All @@ -411,7 +392,8 @@
Yp0 = cat_vol_resize(Yp0,'dereduceV',resTb); %#ok<NASGU>
Ywm = cat_vol_resize(Ywm,'dereduceV',resTb); %#ok<NASGU>
end
%%


labmn = zeros(1,6); for i=[1 2 3 6], if ndims(Ylab{i})==3, labmn(i) = mean(Ylab{i}(Ycls{i}(:)>128)); else, labmn(i) = mean(Ylab{i}); end; end
[labmn,lo] = sort(labmn,'descend'); %clear labmn; %#ok<ASGLU>

Expand All @@ -430,8 +412,6 @@
%% update of the global intensity normalized map
% ######## RD202105: this is not optimal #########
Ymg = Ysrc ./ max(eps,Ylab{2}) * Tth.T3th(5);
%Ymg = Ysrc ./ max(eps,Ylab{2});
%Ymg = Ymg * max( Tthc.T3th(Tthc.T3thx>0 & Tthc.T3thx<4) ) / max( max(Tthc.T3thx(Tthc.T3thx>0 & Tthc.T3thx<4))/3); % RD202004: corrected srcmin-correction
Ymg = cat_main_gintnorm(Ymg,Tth);
if ~debug, clear Ylab Ysrc; end

Expand Down
Loading

0 comments on commit 5914c08

Please sign in to comment.