Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

expand_nii_scan.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. % Expand a multiple-scan NIFTI file into multiple single-scan NIFTI files
  2. %
  3. % Usage: expand_nii_scan(multi_scan_filename, [img_idx], [path_to_save])
  4. %
  5. % NIFTI data format can be found on: http://nifti.nimh.nih.gov
  6. %
  7. % - Jimmy Shen (jimmy@rotman-baycrest.on.ca)
  8. %
  9. function expand_nii_scan(filename, img_idx, newpath)
  10. v = version;
  11. % Check file extension. If .gz, unpack it into temp folder
  12. %
  13. if length(filename) > 2 & strcmp(filename(end-2:end), '.gz')
  14. if ~strcmp(filename(end-6:end), '.img.gz') & ...
  15. ~strcmp(filename(end-6:end), '.hdr.gz') & ...
  16. ~strcmp(filename(end-6:end), '.nii.gz')
  17. error('Please check filename.');
  18. end
  19. if str2num(v(1:3)) < 7.1 | ~usejava('jvm')
  20. error('Please use MATLAB 7.1 (with java) and above, or run gunzip outside MATLAB.');
  21. else
  22. gzFile = 1;
  23. end
  24. end
  25. if ~exist('newpath','var') | isempty(newpath), newpath = pwd; end
  26. if ~exist('img_idx','var') | isempty(img_idx), img_idx = 1:get_nii_frame(filename); end
  27. for i=img_idx
  28. nii_i = load_untouch_nii(filename, i);
  29. fn = [nii_i.fileprefix '_' sprintf('%04d',i)];
  30. pnfn = fullfile(newpath, fn);
  31. if exist('gzFile', 'var')
  32. pnfn = [pnfn '.nii.gz'];
  33. end
  34. save_untouch_nii(nii_i, pnfn);
  35. end
  36. return; % expand_nii_scan