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

조회 수: 1 (최근 30일)
Gülizar Kaya
Gülizar Kaya 2018년 7월 26일
편집: Gülizar Kaya 2018년 8월 31일
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