I want to make an array/matrix of the features extracted of 10 images using detectSURFFeatures. How can I do this?

2 ビュー (過去 30 日間)
This is the code I have.
for i=1:10
num = i;
num_s = num2str(num);
extension = '.bmp';
filename = [num_s extension];
cereal_img = imread(filename);
cereal_img_grey = rgb2gray(cereal_img);
ref_pts = detectSURFFeatures(cereal_img_grey);
[ref_features, ref_validPts] = extractFeatures(cereal_img_grey, ref_pts);
[s1,s2]=size(ref_features);
S=s1*s2;
ftr=reshape(ref_features,1,S);
ref_array(i,:)=ftr;
end
However it is not working. It shows this error:
Unable to perform assignment because the size of the left side is
1-by-49664 and the size of the right side is 1-by-56512.
Error in cereal_array (line 18)
ref_array(i,:)=ftr;

回答 (1 件)

Subhadeep Koley
Subhadeep Koley 2020 年 1 月 9 日
編集済み: Subhadeep Koley 2020 年 1 月 9 日
Saving extracted SURF features in array/matrix is difficult as, the number of extracted features is different for different images. You’re getting this error because the function extractFeatures is extracting features of different dimensions for different images.
As a workaround, you can save them in a cell array very easily. Refer the code below.
ref_array={}; % Declare a blank cell array
for i=1:10
num = i;
num_s = num2str(num);
extension = '.bmp';
filename = [num_s extension];
cereal_img = imread(filename);
cereal_img_grey = rgb2gray(cereal_img);
ref_pts = detectSURFFeatures(cereal_img_grey);
[ref_features, ref_validPts] = extractFeatures(cereal_img_grey, ref_pts);
[s1,s2]=size(ref_features);
S=s1*s2;
ftr=reshape(ref_features,1,S);
ref_array{i}=ftr; % Access each cell via the looping variable 'i'
end
Hope this helps!

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by