I want to make an array/matrix of the features extracted of 10 images using detectSURFFeatures. How can I do this?
조회 수: 1 (최근 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;
댓글 수: 0
답변 (1개)
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!