猪猪虾 发表于 2020-5-1 16:48:54

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

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


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

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

% check spm version:
if exist('spm_select','file') % should be true for spm5
    spm5 = 1;
    select = @(msg) spm_select(inf, 'image', msg);
elseif exist('spm_get','file') % should be true for spm2
    spm5 = 0;
    select = @(msg) spm_get(inf, 'img', msg);
else
    error('Failed to locate spm_get or spm_select; please add SPM to Matlab path')
end

if ( ~exist('files', 'var') || isempty(files) )
    files = select('choose images');
end
if ( ~exist('thr', 'var') || isempty(thr) )
    thr = -inf; % default to include everything (except NaNs)
end
if ~exist('msk', 'var')
    msk = 1; % default to include everything
end
if isempty(msk)
    msk = select('Choose mask image');
end
if ischar(msk)
    msk = spm_vol(msk);
end
if isstruct(msk)
    msk = spm_read_vols(msk);
end
msk = msk ~= 0;
vols = spm_vol(files);
N = length(vols);

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

t = zeros(N,1);
for n = 1:N
    hwait=waitbar(n/N,'请等待>>>>>>>>');
    for nn=1:the_number_of_mask
      Imask=load_nii(strcat('F:\data\t\',num2str(nn),'myMask.img'));   %% add the mask files
      Imask=double(Imask.img);
      msk=Imask;
      vsz = abs(det(vols(n).mat));
      img = spm_read_vols(vols(n));
      img = img .* msk;
      t(n) = sum(img(img > thr)) * vsz / 1000; % vsz in mm^3 (= 0.001 ml)
      HIV_1234vol(n,nn)=t(n);%%fuzhi
    end
    close(hwait);
end
save('HIV_1234vol.mat','HIV_1234vol')


页: [1]
查看完整版本: matlab怎么读取Img格式的文件,60行报错