フィルターのクリア

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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by