5th semester files

This commit is contained in:
2024-02-22 14:23:12 -05:00
parent e39a9fec53
commit 5223b711a6
727 changed files with 1836099 additions and 0 deletions

View File

@ -0,0 +1,31 @@
function bestSubject = knnFace(facePath, k, dctData, dctDim, dctDataClass)
%{
facefile path to the face image file
k the number of close neighbors to find
dctData the pretrained dataset
dctDim the dimesion of DCT data to work with
%}
% Find the number of faces in the dataset
N = length(dctData);
% Get the 1-D feature vector of the DCT of the face
features = findfeatures(facePath, dctDim);
% Find the distance from the face to each face in the dataset
dists = zeros(N, 1);
for idx = 1 : N
% Calculate the Euclidean distance in any dimension (found with 2-norm)
dists(idx) = norm(features' - dctData(idx,:), 2);
end
% Sort the distances in ascending order
[sDists, origIdx] = sort(dists);
% Find the corresponding best subjects for the shortest distances
bestSubjects = zeros(k,1);
for idx = 1 : k
bestSubjects(idx) = dctDataClass(origIdx(idx));
end
bestSubject = mode(bestSubjects);