-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_avw_and_header.m
More file actions
41 lines (34 loc) · 1.3 KB
/
read_avw_and_header.m
File metadata and controls
41 lines (34 loc) · 1.3 KB
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
function [img,dims,scales,bpp,endian,hdr] = read_avw(fname)
% [img, dims,scales,bpp,endian] = READ_AVW(fname)
%
% Read in an Analyze or nifti file into either a 3D or 4D
% array (depending on the header information)
% fname is the filename (must be inside single quotes)
% Note: automatically detects - unsigned char, short, long, float
% double and complex formats
% Extracts the 4 dimensions (dims),
% 4 scales (scales) and bits per pixel (bpp) for voxels
% contained in the Analyze or nifti header file (fname)
% Also returns endian = 'l' for little-endian or 'b' for big-endian
%
% See also: SAVE_AVW
% remove extension if it exists
% KJ: uses spm12 @nifti to read nifti header information of temp file (faster than using spm_vol)
%% convert to uncompressed nifti pair (using FSL)
tmpname = tempname;
command = sprintf('FSLOUTPUTTYPE=NIFTI_PAIR; export FSLOUTPUTTYPE; $FSLDIR/bin/fslmaths %s %s', fname, tmpname);
[status,output]=call_fsl(command);
if (status),
error(output)
end
[dims,scales,bpp,endian,datatype]= read_avw_hdr(tmpname);
if (datatype==32),
% complex type
img=read_avw_complex(tmpname);
else
img=read_avw_img(tmpname);
end
hdr=spm_vol_nifti([tmpname '.hdr']);
% cross platform compatible deleting of files
delete([tmpname,'.hdr']);
delete([tmpname,'.img']);