Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 37 additions & 27 deletions CanlabCore/Data_extraction/timeseries_extract_slice.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 6 additions & 2 deletions CanlabCore/Visualization_functions/Support/movie_tools.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions CanlabCore/hewma_utility/get_ax_slice.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down