From aff39b3c46f0dcf4fc0e3a08a5ea1563112b6054 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:40:53 +0000 Subject: [PATCH 1/2] Initial plan From babb377fd849715d04625b9a9e6bcf7316640a0f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:50:33 +0000 Subject: [PATCH 2/2] Fix deprecated avifile/addframe and all-zeros timeseries_extract_slice Co-authored-by: torwager <6262700+torwager@users.noreply.github.com> --- .../timeseries_extract_slice.m | 64 +++++++++++-------- .../Support/movie_tools.m | 8 ++- .../movie_of_slice_timeseries.m | 8 ++- CanlabCore/hewma_utility/get_ax_slice.m | 10 +-- 4 files changed, 50 insertions(+), 40 deletions(-) diff --git a/CanlabCore/Data_extraction/timeseries_extract_slice.m b/CanlabCore/Data_extraction/timeseries_extract_slice.m index 0cc4d652..e0df3691 100644 --- a/CanlabCore/Data_extraction/timeseries_extract_slice.m +++ b/CanlabCore/Data_extraction/timeseries_extract_slice.m @@ -6,28 +6,25 @@ % :Usage: % :: % -% function sl = timeseries_extract_slice(V,sliceno) +% function sl = timeseries_extract_slice(V, sliceno, orientation) +% +% :Inputs: +% +% **V:** +% image filenames (char) or spm_vol memory-mapped volumes +% +% **sliceno:** +% slice number (voxel index) to extract +% +% **orientation:** +% 'axial' (default), 'sagittal', or 'coronal' +% +% :Output: +% +% **sl:** +% X x Y x time matrix of slice data % - global defaults - - % defaults - switch spm('Ver') - case 'SPM2' - % spm_defaults is a script - disp('WARNING: spm defaults not set for spm2. Make sure your defaults are set correctly'); - - case {'SPM5', 'SPM8', 'SPM12'} - % spm_defaults is a function - spm_defaults() - - otherwise - % unknown SPM - disp('Unknown version of SPM!'); - spm_defaults() - end - - if ischar(V) V = spm_vol(V); end @@ -38,16 +35,29 @@ switch(orientation) case 'axial' - get_slice = @get_ax_slice; + % Map output pixel (x,y) -> voxel (x, y, sliceno) + mat = spm_matrix([0 0 sliceno]); + for i = 1:length(V) + sl(:,:,i) = spm_slice_vol(V(i), mat, V(i).dim(1:2), 0); + end + case 'sagittal' - get_slice = @get_sag_slice; + % Map output pixel (x,y) -> voxel (sliceno, x, y) + % Matrix maps: x_vox=sliceno (const), y_vox=x_pix, z_vox=y_pix + mat = [0 0 0 sliceno; 1 0 0 0; 0 1 0 0; 0 0 0 1]; + for i = 1:length(V) + sl(:,:,i) = spm_slice_vol(V(i), mat, V(i).dim(2:3), 0); + end + case 'coronal' - get_slice = @get_cor_slice; + % Map output pixel (x,y) -> voxel (x, sliceno, y) + % Matrix maps: x_vox=x_pix, y_vox=sliceno (const), z_vox=y_pix + mat = [1 0 0 0; 0 0 0 sliceno; 0 1 0 0; 0 0 0 1]; + for i = 1:length(V) + sl(:,:,i) = spm_slice_vol(V(i), mat, [V(i).dim(1) V(i).dim(3)], 0); + end + otherwise error('Unknown orientation: %s\n', orientation); end - - for i = 1:length(V) - sl(:,:,i) = get_slice(V(i), sliceno); - end end diff --git a/CanlabCore/Visualization_functions/Support/movie_tools.m b/CanlabCore/Visualization_functions/Support/movie_tools.m index 2a16660c..b22d8a69 100644 --- a/CanlabCore/Visualization_functions/Support/movie_tools.m +++ b/CanlabCore/Visualization_functions/Support/movie_tools.m @@ -393,7 +393,10 @@ switch(FRAMESTYLE) case 'avi' % write to avi format directly if isempty(mov) - mov = avifile('mymovie.avi','Quality',75,'Compression','None','Fps',fps); + mov = VideoWriter('mymovie.avi'); + mov.Quality = 75; + mov.FrameRate = fps; + open(mov); end case 'matlab' % matlab movie format @@ -425,7 +428,8 @@ drawnow try - mov = addframe(mov,H); + frame = getframe(H); + writeVideo(mov, frame); catch disp('Cannot write frame. Failed to set stream format??') mov = close(mov); diff --git a/CanlabCore/Visualization_functions/movie_of_slice_timeseries.m b/CanlabCore/Visualization_functions/movie_of_slice_timeseries.m index 88705831..84389664 100644 --- a/CanlabCore/Visualization_functions/movie_of_slice_timeseries.m +++ b/CanlabCore/Visualization_functions/movie_of_slice_timeseries.m @@ -56,7 +56,8 @@ function movie_of_slice_timeseries(imgs, slicenumber, moviename, orientation) title(sprintf('Image %3.0f: %s', i, ff), 'FontSize', 24) % mov = add_a_frame(mov, H); - writeVideo(mov, H); + frame = getframe(H); + writeVideo(mov, frame); end tmp = close(mov); %#ok; @@ -77,7 +78,7 @@ function movie_of_slice_timeseries(imgs, slicenumber, moviename, orientation) % frame_rate = 1/tr; mov = VideoWriter(moviename); - mov.Quality + mov.Quality = 75; mov.FrameRate = fps; open(mov); @@ -96,7 +97,8 @@ function movie_of_slice_timeseries(imgs, slicenumber, moviename, orientation) lightRestoreSingle(H); try - mov = addframe(mov, H); + frame = getframe(H); + writeVideo(mov, frame); catch disp('Cannot write frame. Failed to set stream format??') mov = close(mov); diff --git a/CanlabCore/hewma_utility/get_ax_slice.m b/CanlabCore/hewma_utility/get_ax_slice.m index b9aa0197..448b234f 100644 --- a/CanlabCore/hewma_utility/get_ax_slice.m +++ b/CanlabCore/hewma_utility/get_ax_slice.m @@ -39,16 +39,10 @@ % Transverse slice %========================================================== - C = [1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1]; - DIM = V(1).dim(1:2); + mat = spm_matrix([0 0 slice_num]); - C(3,4) = slice_num; - %C(3,4)=-p; - - % img = rot90(spm_slice_vol(V,C,DIM,0)); - % img = spm_slice_vol(V,inv(C),DIM,0); for i=1:length(V) - slice_data(:,:,i) = spm_slice_vol(V(i), C, DIM, 0); + slice_data(:,:,i) = spm_slice_vol(V(i), mat, V(i).dim(1:2), 0); end slice_data = squeeze(slice_data);