first run at global colour histogram

This commit is contained in:
aj 2019-11-07 16:36:30 +00:00
parent 01ce588a9e
commit cdb3b64ef5
1190 changed files with 260 additions and 6 deletions

9
compareEuclidean.m Normal file
View File

@ -0,0 +1,9 @@
function dst=compareEuclidean(F1, F2)
x=F1-F2;
x=x.^2;
x=sum(x);
dst=sqrt(x);
return;

View File

@ -1,4 +1,4 @@
function dst=cvpr_compare(F1, F2) function dst=cvpr_compare_random(F1, F2)
% This function should compare F1 to F2 - i.e. compute the distance % This function should compare F1 to F2 - i.e. compute the distance
% between the two descriptors % between the two descriptors

View File

@ -32,7 +32,9 @@ for filenum=1:length(allfiles)
imgfname_full=([DATASET_FOLDER,'/Images/',fname]); imgfname_full=([DATASET_FOLDER,'/Images/',fname]);
img=double(imread(imgfname_full))./255; img=double(imread(imgfname_full))./255;
fout=[OUT_FOLDER,'/',OUT_SUBFOLDER,'/',fname(1:end-4),'.mat'];%replace .bmp with .mat fout=[OUT_FOLDER,'/',OUT_SUBFOLDER,'/',fname(1:end-4),'.mat'];%replace .bmp with .mat
F=extractRandom(img);
%% EXTRACT FUNCTION
F=extractGlobalColHist(img);
save(fout,'F'); save(fout,'F');
toc toc
end end

View File

@ -35,10 +35,16 @@ DESCRIPTOR_SUBFOLDER='globalRGBhisto';
ALLFEAT=[]; ALLFEAT=[];
ALLFILES=cell(1,0); ALLFILES=cell(1,0);
ALLCATs=[];
ctr=1; ctr=1;
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp'])); allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
for filenum=1:length(allfiles) for filenum=1:length(allfiles)
fname=allfiles(filenum).name; fname=allfiles(filenum).name;
%identify photo category for PR calculation
split_string = split(fname, '_');
ALLCATs(filenum) = str2double(split_string(1));
imgfname_full=([DATASET_FOLDER,'/Images/',fname]); imgfname_full=([DATASET_FOLDER,'/Images/',fname]);
img=double(imread(imgfname_full))./255; img=double(imread(imgfname_full))./255;
thesefeat=[]; thesefeat=[];
@ -49,6 +55,9 @@ for filenum=1:length(allfiles)
ctr=ctr+1; ctr=ctr+1;
end end
% get counts for each category for PR calculation
CAT_HIST = histogram(ALLCATs).Values;
%% 2) Pick an image at random to be the query %% 2) Pick an image at random to be the query
NIMG=size(ALLFEAT,1); % number of images in collection NIMG=size(ALLFEAT,1); % number of images in collection
queryimg=floor(rand()*NIMG); % index of a random image queryimg=floor(rand()*NIMG); % index of a random image
@ -59,11 +68,56 @@ dst=[];
for i=1:NIMG for i=1:NIMG
candidate=ALLFEAT(i,:); candidate=ALLFEAT(i,:);
query=ALLFEAT(queryimg,:); query=ALLFEAT(queryimg,:);
thedst=cvpr_compare(query,candidate);
dst=[dst ; [thedst i]]; category=ALLCATs(i);
%% COMPARE FUNCTION
thedst=compareEuclidean(query,candidate);
dst=[dst ; [thedst i category]];
end end
dst=sortrows(dst,1); % sort the results dst=sortrows(dst,1); % sort the results
%% 3.5) Calculate PR
precision_values=[];
recall_values=[];
query_row = dst(1,:);
query_category = query_row(1,3);
for i=1:NIMG
rows = dst(1:i, :);
correct_results = 0;
incorrect_results = 0;
for n=1:i
row = rows(n, :);
category = row(3);
if category == query_category
correct_results = correct_results + 1;
else
incorrect_results = incorrect_results + 1;
end
end
precision = correct_results / i;
recall = correct_results / CAT_HIST(1,query_category);
precision_values(i) = precision;
recall_values(i) = recall;
end
% plot PR curve
plot(recall_values, precision_values);
title('PR Curve');
xlabel('Recall');
ylabel('Precision');
% for i=1:NIMG
% [i, " -> p: ", precision_values(i), "r: ", recall_values(i)]
% end
%% 4) Visualise the results %% 4) Visualise the results
%% These may be a little hard to see using imgshow %% These may be a little hard to see using imgshow
%% If you have access, try using imshow(outdisplay) or imagesc(outdisplay) %% If you have access, try using imshow(outdisplay) or imagesc(outdisplay)
@ -77,5 +131,5 @@ for i=1:size(dst,1)
img=img(1:81,:,:); % crop image to uniform size vertically (some MSVC images are different heights) img=img(1:81,:,:); % crop image to uniform size vertically (some MSVC images are different heights)
outdisplay=[outdisplay img]; outdisplay=[outdisplay img];
end end
imgshow(outdisplay); % imgshow(outdisplay);
axis off; % axis off;

129
cvpr_visualsearch.m~ Normal file
View File

@ -0,0 +1,129 @@
%% EEE3032 - Computer Vision and Pattern Recognition (ee3.cvpr)
%%
%% cvpr_visualsearch.m
%% Skeleton code provided as part of the coursework assessment
%%
%% This code will load in all descriptors pre-computed (by the
%% function cvpr_computedescriptors) from the images in the MSRCv2 dataset.
%%
%% It will pick a descriptor at random and compare all other descriptors to
%% it - by calling cvpr_compare. In doing so it will rank the images by
%% similarity to the randomly picked descriptor. Note that initially the
%% function cvpr_compare returns a random number - you need to code it
%% so that it returns the Euclidean distance or some other distance metric
%% between the two descriptors it is passed.
%%
%% (c) John Collomosse 2010 (J.Collomosse@surrey.ac.uk)
%% Centre for Vision Speech and Signal Processing (CVSSP)
%% University of Surrey, United Kingdom
close all;
clear all;
%% Edit the following line to the folder you unzipped the MSRCv2 dataset to
DATASET_FOLDER = 'dataset';
%% Folder that holds the results...
DESCRIPTOR_FOLDER = 'descriptors';
%% and within that folder, another folder to hold the descriptors
%% we are interested in working with
DESCRIPTOR_SUBFOLDER='globalRGBhisto';
%% 1) Load all the descriptors into "ALLFEAT"
%% each row of ALLFEAT is a descriptor (is an image)
ALLFEAT=[];
ALLFILES=cell(1,0);
ALLCATs=[];
ctr=1;
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
for filenum=1:length(allfiles)
fname=allfiles(filenum).name;
%identify photo category for PR calculation
split_string = split(fname, '_');
ALLCATs(filenum) = str2double(split_string(1));
imgfname_full=([DATASET_FOLDER,'/Images/',fname]);
img=double(imread(imgfname_full))./255;
thesefeat=[];
featfile=[DESCRIPTOR_FOLDER,'/',DESCRIPTOR_SUBFOLDER,'/',fname(1:end-4),'.mat'];%replace .bmp with .mat
load(featfile,'F');
ALLFILES{ctr}=imgfname_full;
ALLFEAT=[ALLFEAT ; F];
ctr=ctr+1;
end
% get counts for each category for PR calculation
CAT_HIST = histogram(ALLCATs).Values;
%% 2) Pick an image at random to be the query
NIMG=size(ALLFEAT,1); % number of images in collection
queryimg=floor(rand()*NIMG); % index of a random image
%% 3) Compute the distance of image to the query
dst=[];
for i=1:NIMG
candidate=ALLFEAT(i,:);
query=ALLFEAT(queryimg,:);
category=ALLCATs(i);
%% COMPARE FUNCTION
thedst=compareEuclidean(query,candidate);
dst=[dst ; [thedst i category]];
end
dst=sortrows(dst,1); % sort the results
%% 3.5) Calculate PR
precision_values=[];
recall_values=[];
query_row = dst(1,:);
query_category = query_row(1,3);
for i=1:NIMG
rows = dst(1:i, :);
correct_results = 0;
incorrect_results = 0;
for n=1:i
row = rows(i, :);
category = row(3);
if category == query_category
correct_results = correct_results + 1;
else
incorrect_results = incorrect_results + 1;
end
end
precision = correct_results / i;
recall = correct_results / CAT_HIST(1,query_category);
precision_values(i) = precision;
recall_values(i) = recall;
end
% for i=1:NIMG
% [i, " -> p: ", precision_values(i), "r: ", recall_values(i)]
% end
%% 4) Visualise the results
%% These may be a little hard to see using imgshow
%% If you have access, try using imshow(outdisplay) or imagesc(outdisplay)
SHOW=15; % Show top 15 results
dst=dst(1:SHOW,:);
outdisplay=[];
for i=1:size(dst,1)
img=imread(ALLFILES{dst(i,2)});
img=img(1:2:end,1:2:end,:); % make image a quarter size
img=img(1:81,:,:); % crop image to uniform size vertically (some MSVC images are different heights)
outdisplay=[outdisplay img];
end
imgshow(outdisplay);
axis off;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More