Results from code below (115 fMRI HCP files)
Vol - read
Elapsed time is 4.536723 seconds.
Slice - read
Elapsed time is 4.581537 seconds.
Vol - read and write
Elapsed time is 8.776489 seconds.
Slice - read and write
Elapsed time is 71.972148 seconds.
Code Block | ||
---|---|---|
| ||
function cspm_test_spmreadwrite ( P1, P2 ) % Testing reading and writing by slice vs volume % Copy same files into two different folders % Select each set of files (P1, P2) V1 = spm_vol(P1); V2 = spm_vol(P2); disp('Vol - read ') tic Y1 = spm_read_vols(V1); toc disp('Slice - read') tic nscan = length(V2); Y2 = zeros([V2(1).dim nscan]); dim12 = V2(1).dim(1:2); for z = 1:V2(1).dim(3) for i = 1:nscan Y2(:,:,z,i) = spm_slice_vol(V2(i),spm_matrix([0 0 z]),dim12,0); end end toc disp('Vol - read and write') tic Y1 = spm_read_vols(V1); for i = 1:nscan spm_write_vol(V1(i),Y1(:,:,:,i)); end toc disp('Slice - read and write') tic nscan = length(V2); Y2 = zeros([V2(1).dim nscan]); dim12 = V2(1).dim(1:2); for z = 1:V2(1).dim(3) for i = 1:nscan Y2(:,:,z,i) = spm_slice_vol(V2(i),spm_matrix([0 0 z]),dim12,0); end for i = 1:nscan spm_write_plane(V2(i),Y2(:,:,z,i),z); end end toc end |
...