working mahalanobis

This commit is contained in:
aj 2019-11-30 17:56:27 +00:00
parent aaa4feae09
commit 752243d192
5 changed files with 12 additions and 21 deletions

View File

@ -27,10 +27,10 @@ DATASET_FOLDER = 'dataset';
DESCRIPTOR_FOLDER = 'descriptors'; DESCRIPTOR_FOLDER = 'descriptors';
%% and within that folder, another folder to hold the descriptors %% and within that folder, another folder to hold the descriptors
%% we are interested in working with %% we are interested in working with
DESCRIPTOR_SUBFOLDER='avgRGB'; % DESCRIPTOR_SUBFOLDER='avgRGB';
% DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='globalRGBhisto';
% DESCRIPTOR_SUBFOLDER='spatialColour'; % DESCRIPTOR_SUBFOLDER='spatialColour';
% DESCRIPTOR_SUBFOLDER='spatialColourTexture'; DESCRIPTOR_SUBFOLDER='spatialColourTexture';
CATEGORIES = ["Farm Animal" CATEGORIES = ["Farm Animal"
"Tree" "Tree"
@ -101,10 +101,10 @@ for iteration=1:CAT_TOTAL
%% 3) Compute EigenModel %% 3) Compute EigenModel
E = getEigenModel(ALLFEAT); E = getEigenModel(ALLFEAT);
E = deflateEigen(E, 2); E = deflateEigen(E, 12);
%% 4) Project data to lower dimensionality %% 4) Project data to lower dimensionality
% ALLFEAT=ALLFEAT-repmat(E.org,size(ALLFEAT,1),1); ALLFEAT=ALLFEAT-repmat(E.org,size(ALLFEAT,1),1);
ALLFEAT=((E.vct')*(ALLFEAT'))'; ALLFEAT=((E.vct')*(ALLFEAT'))';
%% 3) Compute the distance of image to the query %% 3) Compute the distance of image to the query
@ -116,7 +116,7 @@ for iteration=1:CAT_TOTAL
category=ALLCATs(i); category=ALLCATs(i);
%% COMPARE FUNCTION %% COMPARE FUNCTION
thedst=compareMahalanobis(E, ALLFEAT, query); thedst=compareMahalanobis(E, query, candidate);
dst=[dst ; [thedst i category]]; dst=[dst ; [thedst i category]];
end end
dst=sortrows(dst,1); % sort the results dst=sortrows(dst,1); % sort the results
@ -134,7 +134,6 @@ for iteration=1:CAT_TOTAL
end end
fprintf('category was %s\n', CATEGORIES(query_category)) fprintf('category was %s\n', CATEGORIES(query_category))
%calculate PR for each n %calculate PR for each n
for i=1:NIMG for i=1:NIMG

View File

@ -1,6 +1,6 @@
function dst=compareL1(F1, F2) function dst=compareL1(F1, F2)
x=F1-F2; x=abs(F1-F2);
dst=sum(x); dst=sum(x);
return; return;

View File

@ -1,17 +1,9 @@
function d=compareMahalanobis(E, obs, query) function d=compareMahalanobis(E, query, candidate)
obs_translated = (obs -repmat(query, size(obs,1), 1))'; x=query-candidate;
x=(x.^2)./(E.val');
x=sum(x);
proj=E.vct*obs_translated; d=sqrt(x);
dstsq=proj.*proj;
E.val(E.val==0)=1; % check for eigenvalues of 0
dst=dstsq./repmat((E.val),1,size(obs,2));
d=sum(dst);
d=sqrt(d);
return; return;

View File

@ -19,7 +19,7 @@ for i = 1:rows
end end
if size(vals, 2) == 0 if size(vals, 2) == 0
F = zeros(1, bins) F = zeros(1, bins);
else else
F= histogram(vals, bins, 'Normalization', 'probability').Values; F= histogram(vals, bins, 'Normalization', 'probability').Values;
end end