I am having this error "Index in position 3 is invalid. Array indices must be positive integers or logical values." in my file. Can you please help me in resolving this.
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhammad
am 13 Apr. 2023
Kommentiert: Muhammad
am 13 Apr. 2023
I am trying to convert dataset from Nifti to PNG but the error is coming.
imds = imageDatastore('D:\DatasetNifti\control2', ...
'IncludeSubfolders',true,'LabelSource','foldernames','FileExtensions','.NII');
for i=1:numel(imds.Files)
info = niftiinfo(imds.Files{i});
x=info.ImageSize;
%fprintf('%d %d %d\n',x(1),x(2),x(3));
Y = niftiread(imds.Files{i});
img=uint16(Y(:,:,x(3)/2));
%imshow(img,[])
s=imds.Files{i};
s(end-2:end)='png';
imwrite(img,s);
end
After running the code below is a error which is coming.
Index in position 3 is invalid. Array indices must be positive integers or logical values.
Error in DataConversion (line 8)
img=uint16(Y(:,:,x(3)/2));
Akzeptierte Antwort
Antoni Garcia-Herreros
am 13 Apr. 2023
Bearbeitet: Antoni Garcia-Herreros
am 13 Apr. 2023
Hello Muhammad,
Most likely your x(3) value will be and odd integer, therfore when you divide it by 2 you'll have a float.
You should round the result of x(3)/2
img=uint16(Y(:,:,round(x(3)/2)));
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Biomedical Imaging finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!