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,40 @@
1
+%  Undo the flipping and rotations performed by xform_nii; spit back only
2
+%  the raw img data block. Initial cut will only deal with 3D volumes
3
+%  strongly assume we have called xform_nii to write down the steps used 
4
+%  in xform_nii.
5
+%
6
+%  Usage:  a = load_nii('original_name');
7
+%          manipulate a.img to make array b;
8
+%
9
+%          if you use unxform_nii to un-tranform the image (img) data
10
+%          block, then nii.original.hdr is the corresponding header.
11
+%
12
+%          nii.original.img = unxform_nii(a, b);
13
+%          save_nii(nii.original,'newname');
14
+%
15
+%  Where, 'newname' is created with data in the same space as the
16
+%         original_name data    
17
+%
18
+%  - Jeff Gunter, 26-JUN-06
19
+%
20
+function outblock = unxform_nii(nii, inblock)
21
+  
22
+   if isempty(nii.hdr.hist.rot_orient)     
23
+      outblock=inblock;
24
+   else
25
+      [dummy unrotate_orient] = sort(nii.hdr.hist.rot_orient);
26
+      outblock = permute(inblock, unrotate_orient);
27
+   end
28
+
29
+   if ~isempty(nii.hdr.hist.flip_orient)
30
+      flip_orient = nii.hdr.hist.flip_orient(unrotate_orient);
31
+
32
+      for i = 1:3
33
+         if flip_orient(i)
34
+            outblock = flipdim(outblock, i);
35
+         end
36
+      end
37
+   end;
38
+
39
+   return;
40
+