Why do I get a Inf/NaN value when I create a 4D double array?

1 次查看(过去 30 天)
Dear experts,
I am trying to calculate an overlap between two masks in nifti format in a loop. The standard mask is binary, the looped one should contain numbers between 0:6.
ID_CODES=dir([wd '*.MRI.1']); %dir of all subjects
ROImask=spm_read_vols(spm_vol('/Data/users/gulizar/verbgen_results/img/outmask_seg_all.nii')); #an image/'mask', containing numbers between 0-6.
for i = 1:length(ID_CODES) % Loop over subjects
dp=fullfile('/Data/users/*/*/',ID_CODES(i).name, '/Images/wseg.nii'); %binary image that differs between the subjects
seg(:,:,:,i)=spm_read_vols(spm_vol(dp)); %spm_read_vols simply reads the file (I don't have the image processing toolbox)
end
segf(:,:,:,:)=flipud(seg(:,:,:,:)); %I do this, because for some reason my files are mirrored
seg2(:,:,:,:)=griddedInterpolant(segf(:,:,:,:));
seg3(:,:,:,:)=seg2({linspace(1, size(segf(:,:,:,:),1),51),linspace(1,size(segf(:,:,:,:),2),75),linspace(1,size(segf(:,:,:,:),3),55),linspace(1,size(segf(:,:,:,:),4),156)}); %changes the dimension of each binary image, so that it is the same as the ROImask dimensions
for i= 1:length(ID_CODES)
locseg(:,:,:,i)=ROImask(:,:,:).*seg3(:,:,:,i); %multiply ROImask with binary mask, for each subject
location(:,:,:,i)=mode(locseg(:,:,:,i)); %most frequent values in overlap between the masks, for each subject; output must be a number between 0-6.
end
When I do this, my output contains a lot of NaN values. In debugging mode I saw this happens early on while defining the variable 'seg'.
>> any(isfinite(seg(:))) --> ans = 1
Any idea why I get NaN values in my output, or an Inf value in 'seg' in the first place? How can I fix this? I tried changing Inf and NaN values to zero after defining seg, but somehow this does not do the trick.
Also I am pretty new in scripting, so any help is very much appreciated!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MRI 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by