forked from rordenlab/spmScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnii_flipap.m
More file actions
executable file
·27 lines (25 loc) · 890 Bytes
/
nii_flipap.m
File metadata and controls
executable file
·27 lines (25 loc) · 890 Bytes
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
function nii_flipap (V)
% Generates anterior-posterior mirrored image (flip on Y dimension)
% V : image(s) to flip
% Examples
% nii_flipap('mri.nii');
% nii_flipap(strvcat('C:\dir\p1.nii','C:\dir\p2.nii')); %scans from participant 1 and 2
if nargin <1 %no files specified
V = spm_select(inf,'image','Select image to left-right flip');
end
fprintf('%s: Flipping order of rows - please make sure this is the left-right axis\n', mfilename);
for i=1:size(V,1)
ref = deblank(V(i,:));
[pth,nam,ext] = spm_fileparts(ref);
hdr = spm_vol(fullfile(pth,[nam ext]));
img = spm_read_vols(hdr);
imgflip = flipdim(img,2);
nvol = numel(hdr);
hdr = hdr(1);
for vol = 1 : nvol
hdr.n(1)=vol;
hdr.fname = fullfile(pth,['AP' nam ext]);
spm_write_vol(hdr,imgflip(:,:,:,vol));
end;
end; %for each image
%end nii_flipap()