鱼C论坛

 找回密码
 立即注册
查看: 2182|回复: 0

matlab怎么读取Img格式的文件,60行报错

[复制链接]
发表于 2020-5-1 16:48:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 猪猪虾 于 2020-5-1 16:57 编辑

  1. function [t, files] = get_totals_revised_by_long(files, thr, msk)
  2. %get_totals - Returns image totals (sum over all voxels), in ml
  3. %  t = get_totals
  4. %  [t files] = get_totals(files, thr, msk)
  5. % GUI file-selection is used if files not specified as argument (or empty).
  6. %
  7. % If thr is given, this will be treated as an absolute threshold
  8. % (i.e. values below this will be zeroed, hence the total will better match
  9. % the GM analysed in

  10. % the voxelwise stats, with the same threshold masking).
  11. %
  12. % Similarly, if msk is specified this image will be used as an explicit
  13. % mask (i.e. only non-zero mask voxels will be included).
  14. % GUI file-selection is used if msk is given as empty string ('').
  15. % [Currently, masking assumes that msk matches the voxel dimensions of each
  16. % image, and that therefore, all images have the same dimensions.]

  17. % check spm version:
  18. if exist('spm_select','file') % should be true for spm5
  19.     spm5 = 1;
  20.     select = @(msg) spm_select(inf, 'image', msg);
  21. elseif exist('spm_get','file') % should be true for spm2
  22.     spm5 = 0;
  23.     select = @(msg) spm_get(inf, 'img', msg);
  24. else
  25.     error('Failed to locate spm_get or spm_select; please add SPM to Matlab path')
  26. end

  27. if ( ~exist('files', 'var') || isempty(files) )
  28.     files = select('choose images');
  29. end
  30. if ( ~exist('thr', 'var') || isempty(thr) )
  31.     thr = -inf; % default to include everything (except NaNs)
  32. end
  33. if ~exist('msk', 'var')
  34.     msk = 1; % default to include everything
  35. end
  36. if isempty(msk)
  37.     msk = select('Choose mask image');
  38. end
  39. if ischar(msk)
  40.     msk = spm_vol(msk);
  41. end
  42. if isstruct(msk)
  43.     msk = spm_read_vols(msk);
  44. end
  45. msk = msk ~= 0;
  46. vols = spm_vol(files);
  47. N = length(vols);

  48. the_number_of_mask=1;  %%
  49. HIV_1234vol=zeros(N, the_number_of_mask);%%dingyimubiao

  50. t = zeros(N,1);
  51. for n = 1:N
  52.     hwait=waitbar(n/N,'请等待>>>>>>>>');
  53.     for nn=1:the_number_of_mask
  54.         Imask=load_nii(strcat('F:\data\t\',num2str(nn),'myMask.img'));   %% add the mask files
  55.         Imask=double(Imask.img);
  56.         msk=Imask;
  57.         vsz = abs(det(vols(n).mat));
  58.         img = spm_read_vols(vols(n));
  59.         img = img .* msk;
  60.         t(n) = sum(img(img > thr)) * vsz / 1000; % vsz in mm^3 (= 0.001 ml)
  61.         HIV_1234vol(n,nn)=t(n);  %%fuzhi
  62.     end
  63.     close(hwait);
  64. end
  65. save('HIV_1234vol.mat','HIV_1234vol')


复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-28 11:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表