Browse code

searchlight ready. missing nifti-image-write support. added timing to FBS

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@167 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on30/03/2009 17:54:25
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,106 @@
1
+%  Load NIFTI or ANALYZE dataset, but not applying any appropriate affine
2
+%  geometric transform or voxel intensity scaling.
3
+%
4
+%  Although according to NIFTI website, all those header information are
5
+%  supposed to be applied to the loaded NIFTI image, there are some
6
+%  situations that people do want to leave the original NIFTI header and
7
+%  data untouched. They will probably just use MATLAB to do certain image
8
+%  processing regardless of image orientation, and to save data back with
9
+%  the same NIfTI header.
10
+%
11
+%  Since this program is only served for those situations, please use it
12
+%  together with "save_untouch_nii.m", and do not use "save_nii.m" or
13
+%  "view_nii.m" for the data that is loaded by "load_untouch_nii.m". For
14
+%  normal situation, you should use "load_nii.m" instead.
15
+%  
16
+%  Usage: nii = load_untouch_nii(filename, [img_idx], [dim5_idx], [dim6_idx], [dim7_idx])
17
+%  
18
+%  filename  - 	NIFTI or ANALYZE file name.
19
+%  
20
+%  img_idx (optional)  -  a numerical array of image volume indices.
21
+%	Only the specified volumes will be loaded. All available image
22
+%	volumes will be loaded, if it is default or empty.
23
+%
24
+%	The number of images scans can be obtained from get_nii_frame.m,
25
+%	or simply: hdr.dime.dim(5).
26
+%
27
+%  dim5_idx (optional)  -  a numerical array of 5th dimension indices.
28
+%	Only the specified range will be loaded. All available range
29
+%	will be loaded, if it is default or empty.
30
+%
31
+%  dim6_idx (optional)  -  a numerical array of 6th dimension indices.
32
+%	Only the specified range will be loaded. All available range
33
+%	will be loaded, if it is default or empty.
34
+%
35
+%  dim7_idx (optional)  -  a numerical array of 7th dimension indices.
36
+%	Only the specified range will be loaded. All available range
37
+%	will be loaded, if it is default or empty.
38
+%
39
+%  Returned values:
40
+%  
41
+%  nii structure:
42
+%
43
+%	hdr -		struct with NIFTI header fields.
44
+%
45
+%	filetype -	Analyze format .hdr/.img (0); 
46
+%			NIFTI .hdr/.img (1);
47
+%			NIFTI .nii (2)
48
+%
49
+%	fileprefix - 	NIFTI filename without extension.
50
+%
51
+%	machine - 	machine string variable.
52
+%
53
+%	img - 		3D (or 4D) matrix of NIFTI data.
54
+%
55
+%  - Jimmy Shen (jimmy@rotman-baycrest.on.ca)
56
+%
57
+function nii = load_untouch_nii(filename, img_idx, dim5_idx, dim6_idx, dim7_idx)
58
+
59
+   if ~exist('filename','var')
60
+      error('Usage: nii = load_untouch_nii(filename, [img_idx], [dim5_idx], [dim6_idx], [dim7_idx])');
61
+   end
62
+
63
+   if ~exist('img_idx','var') | isempty(img_idx)
64
+      img_idx = [];
65
+   end
66
+
67
+   if ~exist('dim5_idx','var') | isempty(dim5_idx)
68
+      dim5_idx = [];
69
+   end
70
+
71
+   if ~exist('dim6_idx','var') | isempty(dim6_idx)
72
+      dim6_idx = [];
73
+   end
74
+
75
+   if ~exist('dim7_idx','var') | isempty(dim7_idx)
76
+      dim7_idx = [];
77
+   end
78
+
79
+   %  Read the dataset header
80
+   %
81
+   [nii.hdr,nii.filetype,nii.fileprefix,nii.machine] = load_nii_hdr(filename);
82
+
83
+   if nii.filetype == 0
84
+      nii.hdr = load_untouch0_nii_hdr(nii.fileprefix,nii.machine);
85
+      nii.ext = [];
86
+   else
87
+      nii.hdr = load_untouch_nii_hdr(nii.fileprefix,nii.machine,nii.filetype);
88
+
89
+      %  Read the header extension
90
+      %
91
+      nii.ext = load_nii_ext(filename);
92
+   end
93
+
94
+   %  Read the dataset body
95
+   %
96
+   [nii.img,nii.hdr] = load_nii_img(nii.hdr,nii.filetype,nii.fileprefix, ...
97
+		nii.machine,img_idx,dim5_idx,dim6_idx,dim7_idx);
98
+
99
+   %  Perform some of sform/qform transform
100
+   %
101
+%   nii = xform_nii(nii, tolerance, preferredForm);
102
+
103
+   nii.untouch = 1;
104
+
105
+   return					% load_untouch_nii
106
+