Hi there,
always good to see my spm2 scripts were actually used by someone ;-)
I recently created the very same function for spm5 (see attached), it
seems to work. Please let me know when there are any problems with it.
Kind regards,
Bas
Juergen Haenggi schreef:
> Dear SPM users
>
> I am looking for a script in order to compute the standard deviation or
> z-scores in images voxel-wise.
> There is a script in the SPM archive
> http://www.jiscmail.ac.uk/cgi-bin/wa.exe?A2=ind06&L=SPM&P=R107731&I=-3
> but it does not run with SPM5.
>
> Thanks
> Best regards
> Juergen
>
> -----------------------------------------------------------
> Juergen Haenggi
> Ph.D. (Dr. des.)
> Division of Neuropsychology
> Institute of Psychology
> University of Zurich
> Binzmuehlestrasse 14, PO Box 25
> 8050 Zurich, Switzerland
> 0041 44 635 73 97 (phone office)
> 0041 76 445 86 84 (phone mobile)
> 0041 44 635 74 09 (fax office)
> BIN 4.D.04 (office room number)
> [log in to unmask] (email)
> http://www.psychologie.uzh.ch/neuropsy/ (website)
> http://www.juergenhaenggi.ch (private website)
> -----------------------------------------------------------
>
--
-------------------------------------------------
Dr. S.F.W. Neggers
Division of Brain Research
Rudolf Magnus Institute for Neuroscience
Utrecht University Medical Center
Visiting : Heidelberglaan 100, 3584 CX Utrecht
Room B.01.1.03
Mail : Huispost A.01.126, P.O. Box 85500
3508 GA Utrecht, the Netherlands
Tel : +31 (0)30 2509609 Fax : +31 (0)30 2505443
E-mail : [log in to unmask]
Web : http://www.fmri.nl/people/bas.html
--------------------------------------------------
function PO=sd_images(PI)
% FORMAT PO=sd_images(PI)
% PI - matrix with rows=input filenames (if empty ([]), filenames can be selected in
% GUI window)
% PO - output filenames
%
% this function calculates the standard deviation, mean, relative
% standard deviation (to mean) and temporal SNR image.
% of the images in PI and saves the result in 3 images (average,sd.img,rsd.img, snr.img)
% the image is saved in the directory of the first image selected
% ________________________________________________
% % SPM2 dependent (SPM2 has to be in matlab path)!
% %W% Bas Neggers 2004 %E%
if ispc
slashstr='\'
else
slashstr='/';
end
if isempty(PI),
PI=spm_select(Inf, 'img', 'Select images to calculate sd');
end
PO='';
VIs = spm_vol(PI);
Data=spm_read_vols(VIs(1));
Average_Data=zeros(size(Data));
SD_Data2=zeros(size(Data));
N=size(PI,1);
for i=1:N,
Data=spm_read_vols(VIs(i));
%disp(i);
Average_Data=Average_Data+Data/N;
end
for i=1:N,
Data=spm_read_vols(VIs(i));
SD_Data2=SD_Data2+(Average_Data-Data).^2;
end
SD_Data=sqrt(SD_Data2/(N-1));
SD_Data_Rel=SD_Data./Average_Data;
SD_Data_SNR=Average_Data./SD_Data;
VO=VIs(1);
isl=findstr(VO.fname,slashstr);
VO.fname = [VO.fname(1:isl(end)),'average.nii'];
spm_write_vol(VO,Average_Data);
PO{1}=VO.fname;
VO.fname = [VO.fname(1:isl(end)),'sd.nii'];
spm_write_vol(VO,SD_Data);
PO{2}=VO.fname;
VO.fname = [VO.fname(1:isl(end)),'rsd.nii'];
spm_write_vol(VO,SD_Data_Rel);
PO{3}=VO.fname;
VO.fname = [VO.fname(1:isl(end)),'snr.nii'];
spm_write_vol(VO,SD_Data_SNR);
PO{4}=VO.fname;
|