forked from bramzandbelt/slice_display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsd_get_slice.m
47 lines (38 loc) · 1.4 KB
/
sd_get_slice.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function slice = sd_get_slice(V, xyzmm, transform, vdims, hold)
% SD_GET_SLICE Obtains information from images
%
% DESCRIPTION
% This function obtains information from images, including header
% specifics, transformation matrix, and slice dimensions and positions.
%
% SYNTAX
% [h_figure, p, settings] = SD_GET_SLICE(layers, settings);
%
% V - 1x1 struct, containing image volume information (see spm_vol)
% xyzmm - 4xN double of voxel coordinates in world space
% transform - 4x4 double, specifying affine transformation matrix
% vdims - 1x3 double, specifying voxel dimensions
% hold - scalar or 1x2 double, specifying interpolation method for
% the for the resampling (see spm_sample_vol)
%
% slice - NxM slice data
%
% .........................................................................
% Bram Zandbelt ([email protected]), Radboud University
% SLICE TO PANEL Selects slice data
%
% hold - see spm_sample_vol
%
% This function largely identical to the sf_slice2panel subfunction in the
% panel function of the slover package that comes with SPM.
%
% to voxel space of image
vixyz = (transform*V.mat) \ xyzmm;
% return voxel values from image volume
if isempty(hold)
hold = 1;
end
slice = spm_sample_vol(V,vixyz(1,:),vixyz(2,:),vixyz(3,:), hold);
% transpose to reverse X and Y for figure
slice = reshape(slice, vdims(1:2))';
end