what does this error mean?"Array formation and parentheses-style indexing with objects of class 'matlab.io​.datastore​.ImageData​store' is not allowed"

조회 수: 38 (최근 30일)
Can someone help me to understand this error please and how to fix it? I am having a dataset of 83 images, It is divided into 5 categories, then i made a synthetic dataset that contains 83 images but with some noise and it is also divided into 5 categories, the first dataset is stored in a folder named 'processsvm' and this folder has subfolders that are named like this. "0", "1","2","3","4" , every image in every subfolder is named like this, 0, 1,2,3 etc. so what is causing this error please?
Array formation and parentheses-style indexing with objects of class 'matlab.io.datastore.ImageDatastore' is not allowed. Use
objects of class 'matlab.io.datastore.ImageDatastore' only as scalars or use a cell array.
Error in HOGDigitClassificationExample (line 56)
imshow(trainingSet(2).ImageLocation{3});
here is the code:
syntheticDir = fullfile('E:\sense\SVMCATA\syn-data');
handwrittenDir = fullfile('E:\sense\SVMCATA\processsvm');
% imageSet recursively scans the directory tree containing the images.
trainingSet = imageDatastore(syntheticDir, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
testSet = imageDatastore(handwrittenDir, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
In this example, the training set consists of 101 images for each of the 10 digits. The test set consists of 12 images per digit.
% Show training and test samples
figure;
subplot(2,3,1);
imshow(trainingSet(2).ImageLocation{3});
subplot(2,3,2);
imshow(trainingSet(4).ImageLocation{2});
subplot(2,3,3);
imshow(trainingSet(5).ImageLocation{4});
subplot(2,3,4);
imshow(testSet(2).ImageLocation{2});
subplot(2,3,5);
imshow(testSet(4).ImageLocation{5});
subplot(2,3,6);
imshow(testSet(5).ImageLocation{2});
Prior to training and testing a classifier, a pre-processing step is applied to remove noise artifacts introduced while collecting the image samples. This provides better feature vectors for training the classifier.
% Show pre-processing results
exTestImage = read(testSet(4), 5);
processedImage = imbinarize(exTestImage);
figure;
subplot(1,2,1)
imshow(exTestImage)
subplot(1,2,2)
imshow(processedImage)
img = read(trainingSet(3), 4);
% Extract HOG features and HOG visualization
[hog_2x2, vis2x2] = extractHOGFeatures(img,'CellSize',[2 2]);
[hog_4x4, vis4x4] = extractHOGFeatures(img,'CellSize',[4 4]);
[hog_8x8, vis8x8] = extractHOGFeatures(img,'CellSize',[8 8]);
% Show the original image
figure;
subplot(2,3,1:3); imshow(img);
% Visualize the HOG features
subplot(2,3,4);
plot(vis2x2);
title({'CellSize = [2 2]'; ['Feature length = ' num2str(length(hog_2x2))]});
subplot(2,3,5);
plot(vis4x4);
title({'CellSize = [4 4]'; ['Feature length = ' num2str(length(hog_4x4))]});
subplot(2,3,6);
plot(vis8x8);
title({'CellSize = [8 8]'; ['Feature length = ' num2str(length(hog_8x8))]});
cellSize = [4 4];
hogFeatureSize = length(hog_4x4);
%%Train a Digit Classifier
% Digit classification is a multiclass classification problem, where you
trainingFeatures = [];
trainingLabels = [];
for processsvm = 1:numel(trainingSet)
numImages = trainingSet(processsvm).Count;
features = zeros(numImages, hogFeatureSize, 'single');
for i = 1:numImages
img = read(trainingSet(processsvm), i);
% Apply pre-processing steps
img = imbinarize(img);
features(i, :) = extractHOGFeatures(img, 'CellSize', cellSize);
end
% Use the imageSet Description as the training labels. The labels are
% the digits themselves, e.g. '0', '1', '2', etc.
labels = repmat(trainingSet(processsvm).Description, numImages, 1);
trainingFeatures = [trainingFeatures; features]; %#ok<AGROW>
trainingLabels = [trainingLabels; labels ]; %#ok<AGROW>
end
Next, train a classifier using the extracted features.
% fitcecoc uses SVM learners and a 'One-vs-One' encoding scheme.
classifier = fitcecoc(trainingFeatures, trainingLabels);
[testFeatures, testLabels] = helperExtractHOGFeaturesFromImageSet(testSet, hogFeatureSize, cellSize);
% Make class predictions using the test features.
predictedLabels = predict(classifier, testFeatures);
confMat = confusionmat(testLabels, predictedLabels);
helperDisplayConfusionMatrix(confMat)

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 16일
imageDatastore objects cannot be indexed. They are not arrays. You cannot concatenate two imageDatastore objects to form an array of imageDatastore objects.
imageDatastore objects also have no ImageLocation property or method.
Your access code is written as if you were using imageSet rather than imageDatastore. imageSet is specific to the Computer Vision toolbox; imageDatastore is in all of MATLAB.

추가 답변 (1개)

Omar Crypps
Omar Crypps 2016년 12월 8일
Ok you get it , so can you give me an idea to solve this error ?
Array formation and parentheses-style indexing with objects of class 'comm.PhaseNoise' is not allowed. Use objects of class 'comm.PhaseNoise' only as scalars or use a cell array
it seems to be the same problem
  댓글 수: 3
Iqra Saleem
Iqra Saleem 2019년 1월 30일
I am trying to run the below code but this error occurs:
(( Array formation and parentheses-style indexing with objects of class 'vision.VideoFileReader' is not allowed. Use objects of class
'vision.VideoFileReader' only as scalars or use a cell array.
Error in Untitled2 (line 6)
videoFrame = videoFReader(); ))
%MY CODE IS:
clear all
videoFReader = vision.VideoFileReader('akiyo_CIF.mjpg');
videoPlayer = vision.VideoPlayer;
while ~isDone(videoFReader)
videoFrame = videoFReader();
videoPlayer(videoFrame);
pause(0.1)
end

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by