Thank you very much!
I would have needed to do something exactly like this next week!
I'll let you know in case I have problems.
Regards,
Luca
________________________________________
Da: SPM (Statistical Parametric Mapping) <[log in to unmask]> per conto di Thomas Ernst <[log in to unmask]>
Inviato: martedì 30 luglio 2019 15:00:50
A: [log in to unmask]
Oggetto: Re: [SPM] How to build a customised mip outline (glass brain background)?
Dear experts,
Sometimes a night of sleep is all it takes. Seems pretty clear now that those sparse logicals in MIP.mat actually are the 2D images in question, and there is little else to it. As for the rest, spm_project does most of the magic then.
Well now, starting from this I wrote the short script below to build a modified MIP background. Maybe it is of use to someone trying to do similar stuff. If you find any errors in the script or my interpretation please let me know.
Best regards,
Thomas
code:
% this is a script to build a projection background to use e.g. with
% spm_results from some 3d volume
% define file names
fn_mipOriginal = fullfile(spm('dir'),'MIP.mat');
fn_mipNew = fullfile(spm('dir'),'MIP_cerebellum.mat');
% select an approriate source file to transform
fn_sourceVol = fullfile(spm('dir'),'toolbox','suit','atlas',...
'Cerebellum-SUIT.nii');
% add some descriptive text
descrip = ['This is a projection background for SPM results displaying '...
'the outline of ''Cerebellum-SUIT.nii''. Does only work for '...
'volumetric datasets, not frequency or time datasets.' ];
% load datasets
load(fn_mipNew,'grid_all','mask_all','CXYZ','DXYZ','scale');
i1 = spm_vol(fn_sourceVol);
[Z,XYZ] = spm_read_vols(i1);
%% important: edit offset
CXYZ = CXYZ + [-1,44,29]; % for center of fourth ventricel
% threshold and reduce source dataset
ind = Z > prctile(unique(Z(:)),2); % threshold the image at some level
% percentile is just one possible
% choice
XYZ = XYZ(1:3,ind); % select only non-zero data points
Z = ones(1,sum(ind(:))); % set all non-zero data values to 1
% build temporary mask
dim = [1 1 1 sum(DXYZ(1:2)) sum(DXYZ([1,3]))];
units = {'mm' 'mm' 'mm'};
temp_mask = spm_project(Z,round(XYZ),dim,DXYZ,CXYZ);
% useful for temporary checks:
% figure
% spm_mip(Z,XYZ,eye(3),units);
% get proper background box outlines from original masks and fill it
bg = full(mask_all);
bg0 = bwlabel(bg); % finds 3 clusters corresponding to three outlines
for i=1:3
ind11 = min(mod(find(bg0==i),size(bg0,1)));
ind12 = max(mod(find(bg0==i),size(bg0,1)));
ind13 = min(mod(find(bg0'==i),size(bg0,2)));
ind14 = max(mod(find(bg0'==i),size(bg0,2)));
bg(ind11:ind12,ind13:ind14) = true;
end
% remove cerebellar mask from outlines and build sparse logical
mask_all = sparse((bg-temp_mask)>0);
% save relevant fields
save(fn_mipNew,'grid_all','mask_all','CXYZ','DXYZ','scale','descrip');
% set new mip to default background for projections
spm_get_defaults('stats.results.mipmat',fn_mipNew);
% try displaying some results now
[5xmille]<http://www.5xmille.org/?utm_source=mail&utm_medium=web_link&utm_campaign=5xmille_2018>
5xmille. INSIEME POSSIAMO continuare a scoprire nuove cure.
CODICE FISCALE 07636600962
Rispetta l’ambiente: non stampare questa mail se non è necessario.
Respect the environment: print this email only if necessary.
|