An error " Subscripted assignment dimension mismatch" on line ' features(i​,:)=extrac​tHOGFeatur​es(img,'Ce​llSize',ce​llsize);' what might be the problem for the given code?

1 次查看(过去 30 天)
clc;
close all;
clear all;
DatabaseDir=fullfile(toolboxdir('vision'),'elephants','dataset');
TestDir=fullfile(toolboxdir('vision'),'elephants','testset');
Dataset=imageSet(DatabaseDir,'recursive');
Testset=imageSet(TestDir,'recursive');
%dataset images
figure;
subplot(1,2,1);
imshow(Dataset(1).ImageLocation{1});
subplot(1,2,2);
imshow(Dataset(1).ImageLocation{2});
%testset images
figure;
subplot(1,2,1);
imshow(Testset(1).ImageLocation{1});
subplot(1,2,2);
imshow(Testset(1).ImageLocation{2});
img = read(Dataset(1), 4);
[hog_4x4, vis4x4] = extractHOGFeatures(img,'CellSize',[4 4]);
cellsize = [4 4];
hogFeatureSize = length(hog_4x4);
trainFeatures=[];
trainLabels=[];
l=numel(Dataset);
for i=1:l
numimages=Dataset(i).Count;
features=zeros(numimages,hogFeatureSize,'single');
for j=1:numimages
img=read(Dataset(i),j);
level=graythresh(img);
img=im2bw(img,level);
features(i,:)=extractHOGFeatures(img,'CellSize',cellsize);
end;
labels = repmat(trainingSet(digit).Description, numimages, 1);
trainFeatures=[trainingFeaturres;features];
trainLabels=[trainingLabels;labels];
end
% fitcecoc uses SVM learners and a 'One-vs-One' encoding scheme.
classifier = fitcecoc(trainFeatures, trainLabels);

采纳的回答

Walter Roberson
Walter Roberson 2015-8-31
That code relies upon all the images in the dataset collection being nearly exactly the same size -- mod(size(TheImage),4) has to be the same for all of them. If that is not the case then the number of HOG features is going to be different for some of the images.
A common way to handle this is to imresize() to the same size for all of the images.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by