我是 SVM 的新手,我对分割图像中的两个不同对象(苹果和葡萄)感兴趣。为了训练,我通过提取的苹果和葡萄创建了新图像 (812x185)。但是,当我使用 MATLAB SVM 测试包含苹果和葡萄的图像,我只收到一个对象的类,而不是两个对象的片段。有人可以帮我解决我做错了什么吗?
source={'apple1.jpg','apple2.jpg','apple3.jpg','grape1.jpg', ...
'grape2.jpg','grape3.jpg'};
nfiles = 6;
for i = 1:nfiles
currentfilename = source{i}
currentimage = imread(currentfilename);
images{i} = currentimage;
images{i} = im2double(images{i});
images{i} = rgb2gray(images{i});
images{i} = imresize(images{i},[900 700]);
images{i} = reshape(images{i}', 1, size(images{i},1)*size(images{i},2));
end
trainData = zeros(nfiles, 630000);
for ii=1:nfiles
trainData(ii,:) = images{ii};
end
class = [1 1 1 -1 -1 -1];
SVMStruct = svmtrain (trainData, class);
inputImg = imread('test_image.jpg');
inputImg = im2double(inputImg);
inputImg = rgb2gray(inputImg);
images{i} = imresize(images{i},[900 700]);
inputImg = reshape (inputImg', 1, size(inputImg,1)*size(inputImg,2));
result = svmclassify(SVMStruct, inputImg);