An error " Subscripted assignment dimension mismatch" on line ' features(i,:)=extractHOGFeatures(img,'CellSize',cellsize);' 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);
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!