save_avw.m 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function save_avw(img,fname,vtype,vsize)
  2. % SAVE_AVW(img,fname,vtype,vsize)
  3. %
  4. % Create and save an analyse header (.hdr) and image (.img) file
  5. % for either a 2D or 3D or 4D array (automatically determined).
  6. % fname is the filename (must be inside single quotes)
  7. %
  8. % vtype is 1 character: 'b'=unsigned byte, 's'=short, 'i'=int, 'f'=float
  9. % 'd'=double or 'c'=complex
  10. % vsize is a vector [x y z tr] containing the voxel sizes in mm and
  11. % the tr in seconds (defaults: [1 1 1 3])
  12. %
  13. % See also: READ_AVW
  14. %
  15. %% Save a temp volume in Analyze format
  16. tmpname = tempname;
  17. if ((~isreal(img)) & (vtype~='c')),
  18. disp('WARNING:: Overwriting type - saving as complex');
  19. save_avw_complex(img,tmpname,vsize);
  20. else
  21. if (vtype=='c'),
  22. save_avw_complex(img,tmpname,vsize);
  23. else
  24. save_avw_hdr(img,tmpname,vtype,vsize);
  25. save_avw_img(img,tmpname,vtype);
  26. end
  27. end
  28. %% Convert volume from Analyze format to user's default
  29. tmp=sprintf('! $FSLDIR/bin/avwmaths %s %s\n',tmpname,fname);
  30. eval(tmp);
  31. tmp=sprintf('! /bin/rm %s.hdr %s.img \n',tmpname,tmpname);
  32. eval(tmp);