Error while using PCA for image recognition?

조회 수: 1 (최근 30일)
Anjana Rao
Anjana Rao 2014년 3월 11일
댓글: suchetha n 2021년 1월 1일
Hello!
I've used this code for image recognition using PCA. I keep getting this error:
Error using -
Integers can only be combined with integers of the same class, or scalar doubles.
Error in pirnccompanal (line 43)
feature_vec = evectors' * (input_image(:) - mean_face);
----------------------------------------------------------------------------------------------
Can someone tell me what is wrong with the code? All the images used have dimensions of 60x60. gest1Cell is a cell of 30 images in grayscale (60x60).
Thank you for your time!
clc;
clear all;
gestdatabase;
input_image = gest1Cell{25};
images = [];
image_dims = [60, 60];
num_images = 30;
for n = 1:30
img = gest1Cell{n};
if n == 1
images = zeros(prod(image_dims), num_images);
end
images(:, n) = img(:);
end
% TRAINING
% steps 1 and 2: find the mean image and the mean-shifted input images
mean_face = mean(images, 2);
shifted_images = images - repmat(mean_face, 1, num_images);
% steps 3 and 4: calculate the ordered eigenvectors and eigenvalues
[evectors, score, evalues] = pca(images');
% step 5: only retain the top 'num_eigenfaces' eigenvectors (i.e. the principal components)
num_eigenfaces = 20;
evectors = evectors(:, 1:num_eigenfaces);
% step 6: project the images into the subspace to generate the feature vectors
features = evectors' * shifted_images;
% TESTING AND CLASSIFICATION
% calculate the similarity of the input to each training image
feature_vec = evectors' * (input_image(:) - mean_face);
similarity_score = arrayfun(@(n) 1 / (1 + norm(features(:,n) - feature_vec)), 1:num_images);
% find the image with the highest similarity
[match_score, match_ix] = max(similarity_score);
% display the result
figure, imshow([input_image reshape(images(:,match_ix), image_dims)]);
title(sprintf('matches %s, score %f', filenames(match_ix).name, match_score));
  댓글 수: 1
suchetha n
suchetha n 2021년 1월 1일
For calculating similarity score which method is used?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2014년 3월 11일
Try casting everything to double before doing the math.

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by