필터 지우기
필터 지우기

Index exceeds the number of array elements. Index must not exceed 0.

조회 수: 2 (최근 30일)
Max Walliam
Max Walliam 2021년 11월 27일
댓글: Walter Roberson 2021년 11월 29일
clc;
clear all;
fpath='/MATLAB Drive/HGG';
filepath=fullfile(fpath,'A');
imageDir = fullfile(fpath,'A');
labelDir = fullfile(fpath,'A');
imds = imageDatastore(imageDir,'IncludeSubfolders',true,'FileExtensions','.nii','ReadFcn',@(x) niftiread(x));
classNames = ["background","tumor"];
pixelLabelID = [0 1];
pxds = pixelLabelDatastore(labelDir,classNames,pixelLabelID,'FileExtensions','.nii','ReadFcn',@(x) niftiread(x));
patchSize = [132 132 132];
patchPerImage = 16;
miniBatchSize = 8;
patchds = randomPatchExtractionDatastore(imds,pxds,patchSize,'PatchesPerImage',patchPerImage);
patchds.MiniBatchSize = miniBatchSize;
dsTrain = transform(patchVolDS,@(x) preprocessVolumetricPatchDS(x));
minibatch = read(dsTrain)
function data = niftiread(x)
data = niftiread(x);
if ndims(data) == 3
data = rgb2gray(data);
end
data = im2uint8(mat2gray(data));
end
function batchOut = preprocessVolumetricPatchDS(batchIn)
numRows = size(batchIn,1);
batchOut = batchIn;
% 5 augmentations: nil,rot90,fliplr,flipud,rot90(fliplr)
augType = {@(x) x,@rot90,@fliplr,@flipud,@(x) rot90(fliplr(x))};
for idx = 1:numRows
img = batchIn{idx,1}{1};
resp = batchIn{idx,2}{1};
rndIdx = randi(5,1);
imgAug = augType{rndIdx}(img);
respAug = augType{rndIdx}(resp);
batchOut(idx,:) = {imgAug,respAug};
end
end
Error
Error using matlab.io.datastore.ImageDatastore/readimage (line 32)
Index exceeds the number of array elements. Index must not exceed 0.
Error in matlab.io.datastore.PixelLabelDatastore/readimage (line 574)
[C, info] = readimage(this.ImageDatastore,i);
Error in matlab.io.datastore.PixelLabelDatastore/preview (line 407)
C = readimage(this,1);
Error in randomPatchExtractionDatastore (line 325)
this.NumPixelLabelsDims = ndims(preview(this.dsSecondInternal));
Error in Suntitled (line 14)
patchds = randomPatchExtractionDatastore(imds,pxds,patchSize,'PatchesPerImage',patchPerImage);
  댓글 수: 3
Max Walliam
Max Walliam 2021년 11월 27일
there are images .nii format and the error is
Index exceeds the number of array elements. Index must not exceed 0
Walter Roberson
Walter Roberson 2021년 11월 29일
There are no .nii files being found in /MATLAB Drive/HGG/A or any subdirectory of that directory.

댓글을 달려면 로그인하십시오.

답변 (1개)

yanqi liu
yanqi liu 2021년 11월 29일
sir,may be check the data folder,such as
clc;
clear all;
fpath='/MATLAB Drive/HGG';
filepath=fullfile(fpath,'A');
imageDir = fullfile(fpath,'A');
labelDir = fullfile(fpath,'A');
fs = ls(fulfile(imageDir, '*.nii'));
disp(fs)
fs2 = ls(fulfile(labelDir, '*.nii'));
disp(fs2)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by