An error " Subscripted assignment dimension mismatch" on line ' features(i,:)=extractHOGFeatures(img,'CellSize',cellsize);' what might be the problem for the given code?
1 view (last 30 days)
Show older comments
NANDHU BINOY
on 31 Aug 2015
Answered: Walter Roberson
on 31 Aug 2015
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 Comments
Accepted Answer
Walter Roberson
on 31 Aug 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!