diff --git a/cvpr_computedescriptors.m b/cvpr_computedescriptors.m index 63099be..2f765b8 100644 --- a/cvpr_computedescriptors.m +++ b/cvpr_computedescriptors.m @@ -22,8 +22,8 @@ OUT_FOLDER = 'descriptors'; %% and within that folder, create another folder to hold these descriptors %% the idea is all your descriptors are in individual folders - within %% the folder specified as 'OUT_FOLDER'. -OUT_SUBFOLDER='avgRGB'; -% OUT_SUBFOLDER='globalRGBhisto'; +% OUT_SUBFOLDER='avgRGB'; +OUT_SUBFOLDER='globalRGBhisto'; % OUT_SUBFOLDER='spatialColour'; % OUT_SUBFOLDER='spatialColourTexture'; @@ -37,9 +37,9 @@ for filenum=1:length(allfiles) fout=[OUT_FOLDER,'/',OUT_SUBFOLDER,'/',fname(1:end-4),'.mat'];%replace .bmp with .mat %% EXTRACT FUNCTION - F=extractAvgRGB(img); -% F=extractGlobalColHist(img); -% F=extractSpatialColour(img); +% F=extractAvgRGB(img); + F=extractGlobalColHist(img); +% F=extractSpatialColour(img, 2, 1); % F=extractSpatialColourTexture(img); save(fout,'F'); toc diff --git a/cvpr_visualsearch.m b/cvpr_visualsearch.m index 9fa1c3f..948cc1f 100644 --- a/cvpr_visualsearch.m +++ b/cvpr_visualsearch.m @@ -161,17 +161,7 @@ for run=1:run_total %% 5) calculate AP - P_rel_n = zeros([1, NIMG]); - for i = 1:NIMG - precision = precision_values(i); - i_result_relevant = correct_at_n(i); - - P_rel_n(i) = precision * i_result_relevant; - end - - sum_P_rel_n = sum(P_rel_n); - average_precision = sum_P_rel_n / CAT_HIST(1,query_category); - + average_precision = sum(precision_values .* correct_at_n) / CAT_HIST(1,run); AP_values(run) = average_precision; diff --git a/cvpr_visualsearch_pca_image.m b/cvpr_visualsearch_pca_image.m index e41de99..1bde2a3 100644 --- a/cvpr_visualsearch_pca_image.m +++ b/cvpr_visualsearch_pca_image.m @@ -28,9 +28,9 @@ DESCRIPTOR_FOLDER = 'descriptors'; %% and within that folder, another folder to hold the descriptors %% we are interested in working with % DESCRIPTOR_SUBFOLDER='avgRGB'; -% DESCRIPTOR_SUBFOLDER='globalRGBhisto'; +DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='spatialColour'; -DESCRIPTOR_SUBFOLDER='spatialColourTexture'; +% DESCRIPTOR_SUBFOLDER='spatialColourTexture'; CATEGORIES = ["Farm Animal" "Tree" @@ -93,6 +93,9 @@ NIMG=size(ALLFEAT,1); % number of images in collection confusion_matrix = zeros(CAT_TOTAL); +all_precision = []; +all_recall = []; + AP_values = zeros([1, CAT_TOTAL]); for iteration=1:CAT_TOTAL @@ -101,7 +104,7 @@ for iteration=1:CAT_TOTAL %% 3) Compute EigenModel E = getEigenModel(ALLFEAT); - E = deflateEigen(E, 12); + E = deflateEigen(E, 3); %% 4) Project data to lower dimensionality ALLFEAT=ALLFEAT-repmat(E.org,size(ALLFEAT,1),1); @@ -122,10 +125,10 @@ for iteration=1:CAT_TOTAL dst=sortrows(dst,1); % sort the results %% 4) Calculate PR - precision_values=zeros([1, NIMG]); - recall_values=zeros([1, NIMG]); + precision_values=zeros([1, NIMG-1]); + recall_values=zeros([1, NIMG-1]); - correct_at_n=zeros([1, NIMG]); + correct_at_n=zeros([1, NIMG-1]); query_row = dst(1,:); query_category = query_row(1,3); @@ -134,9 +137,12 @@ for iteration=1:CAT_TOTAL end fprintf('category was %s\n', CATEGORIES(query_category)) + dst = dst(2:NIMG, :); + %calculate PR for each n - for i=1:NIMG - + for i=1:size(dst, 1) + % NIMG-1 and j iterator variable is in order to skip calculating for query image + rows = dst(1:i, :); correct_results = 0; @@ -168,7 +174,7 @@ for iteration=1:CAT_TOTAL end precision = correct_results / i; - recall = correct_results / CAT_HIST(1,iteration); + recall = correct_results / (CAT_HIST(1,iteration) - 1); precision_values(i) = precision; recall_values(i) = recall; @@ -176,28 +182,23 @@ for iteration=1:CAT_TOTAL %% 5) calculate AP - P_rel_n = zeros([1, NIMG]); - for i = 1:NIMG - precision = precision_values(i); - i_result_relevant = correct_at_n(i); - - P_rel_n(i) = precision * i_result_relevant; - end - - sum_P_rel_n = sum(P_rel_n); - average_precision = sum_P_rel_n / CAT_HIST(1,iteration) - + average_precision = sum(precision_values .* correct_at_n) / CAT_HIST(1,iteration); AP_values(iteration) = average_precision; - + + all_precision = [all_precision ; precision_values]; + all_recall = [all_recall ; recall_values]; + %% 6) plot PR curve figure(1) - plot(recall_values, precision_values); + plot(recall_values, precision_values,'LineWidth',1.5); hold on; title('PR Curve'); xlabel('Recall'); ylabel('Precision'); + xlim([0 1]); + ylim([0 1]); %% 7) Visualise the results @@ -222,6 +223,17 @@ for iteration=1:CAT_TOTAL end +%% Plot average PR curve +figure(4) +mean_precision = mean(all_precision); +mean_recall = mean(all_recall); +plot(mean_recall, mean_precision,'LineWidth',5); +title('PR Curve'); +xlabel('Average Recall'); +ylabel('Average Precision'); +xlim([0 1]); +ylim([0 1]); + % normalise confusion matrix norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all'); diff --git a/cvpr_visualsearch_rand_image.m b/cvpr_visualsearch_rand_image.m index 14ec31f..37bd61c 100644 --- a/cvpr_visualsearch_rand_image.m +++ b/cvpr_visualsearch_rand_image.m @@ -163,17 +163,7 @@ for iteration=1:CAT_TOTAL %% 5) calculate AP - P_rel_n = zeros([1, NIMG]); - for i = 1:NIMG - precision = precision_values(i); - i_result_relevant = correct_at_n(i); - - P_rel_n(i) = precision * i_result_relevant; - end - - sum_P_rel_n = sum(P_rel_n); - average_precision = sum_P_rel_n / CAT_HIST(1,iteration) - + average_precision = sum(precision_values .* correct_at_n) / CAT_HIST(1,iteration); AP_values(iteration) = average_precision; diff --git a/cvpr_visualsearch_selected_image.m b/cvpr_visualsearch_selected_image.m index da7b94c..9ccafb9 100644 --- a/cvpr_visualsearch_selected_image.m +++ b/cvpr_visualsearch_selected_image.m @@ -28,9 +28,9 @@ DESCRIPTOR_FOLDER = 'descriptors'; %% and within that folder, another folder to hold the descriptors %% we are interested in working with % DESCRIPTOR_SUBFOLDER='avgRGB'; -% DESCRIPTOR_SUBFOLDER='globalRGBhisto'; +DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='spatialColour'; -DESCRIPTOR_SUBFOLDER='spatialColourTexture'; +% DESCRIPTOR_SUBFOLDER='spatialColourTexture'; CATEGORIES = ["Farm Animal" "Tree" @@ -93,6 +93,9 @@ NIMG=size(ALLFEAT,1); % number of images in collection confusion_matrix = zeros(CAT_TOTAL); +all_precision = []; +all_recall = []; + AP_values = zeros([1, CAT_TOTAL]); for iteration=1:CAT_TOTAL @@ -114,10 +117,10 @@ for iteration=1:CAT_TOTAL dst=sortrows(dst,1); % sort the results %% 4) Calculate PR - precision_values=zeros([1, NIMG]); - recall_values=zeros([1, NIMG]); + precision_values=zeros([1, NIMG-1]); + recall_values=zeros([1, NIMG-1]); - correct_at_n=zeros([1, NIMG]); + correct_at_n=zeros([1, NIMG-1]); query_row = dst(1,:); query_category = query_row(1,3); @@ -126,16 +129,18 @@ for iteration=1:CAT_TOTAL end fprintf('category was %s\n', CATEGORIES(query_category)) - + dst = dst(2:NIMG, :); + %calculate PR for each n - for i=1:NIMG + for i=1:size(dst, 1) + % NIMG-1 and j iterator variable is in order to skip calculating for query image rows = dst(1:i, :); correct_results = 0; incorrect_results = 0; - if i > 1 + if i > 1 for n=1:i - 1 row = rows(n, :); category = row(3); @@ -161,7 +166,7 @@ for iteration=1:CAT_TOTAL end precision = correct_results / i; - recall = correct_results / CAT_HIST(1,iteration); + recall = correct_results / (CAT_HIST(1,iteration) - 1); precision_values(i) = precision; recall_values(i) = recall; @@ -169,28 +174,23 @@ for iteration=1:CAT_TOTAL %% 5) calculate AP - P_rel_n = zeros([1, NIMG]); - for i = 1:NIMG - precision = precision_values(i); - i_result_relevant = correct_at_n(i); - - P_rel_n(i) = precision * i_result_relevant; - end - - sum_P_rel_n = sum(P_rel_n); - average_precision = sum_P_rel_n / CAT_HIST(1,iteration); - + average_precision = sum(precision_values .* correct_at_n) / CAT_HIST(1,iteration); AP_values(iteration) = average_precision; - + + all_precision = [all_precision ; precision_values]; + all_recall = [all_recall ; recall_values]; + %% 6) plot PR curve - figure(1) - plot(recall_values, precision_values); - hold on; - title('PR Curve'); - xlabel('Recall'); - ylabel('Precision'); +% figure(1) +% plot(recall_values, precision_values,'LineWidth',1.5); +% hold on; +% title('Global Colour Histogram PR (n=20)'); +% xlabel('Recall'); +% ylabel('Precision'); +% xlim([0 1]); +% ylim([0 1]); %% 7) Visualise the results @@ -215,6 +215,17 @@ for iteration=1:CAT_TOTAL end +%% Plot average PR curve +figure(4) +mean_precision = mean(all_precision); +mean_recall = mean(all_recall); +plot(mean_recall, mean_precision,'LineWidth',5); +title('Global Colour Histogram Average PR (n=5)'); +xlabel('Average Recall'); +ylabel('Average Precision'); +xlim([0 1]); +ylim([0 1]); + % normalise confusion matrix norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all'); diff --git a/data/colourHistogram/map-line.png b/data/colourHistogram/map-line.png new file mode 100644 index 0000000..ba84ea7 Binary files /dev/null and b/data/colourHistogram/map-line.png differ diff --git a/data/colourHistogram/pr-curves-n-2-avg.png b/data/colourHistogram/pr-curves-n-2-avg.png new file mode 100644 index 0000000..8f04ea8 Binary files /dev/null and b/data/colourHistogram/pr-curves-n-2-avg.png differ diff --git a/data/colourHistogram/pr-curves-n-2.png b/data/colourHistogram/pr-curves-n-2.png new file mode 100644 index 0000000..886ba6f Binary files /dev/null and b/data/colourHistogram/pr-curves-n-2.png differ diff --git a/data/colourHistogram/pr-curves-n-20-avg.png b/data/colourHistogram/pr-curves-n-20-avg.png new file mode 100644 index 0000000..8cae479 Binary files /dev/null and b/data/colourHistogram/pr-curves-n-20-avg.png differ diff --git a/data/colourHistogram/pr-curves-n-20.png b/data/colourHistogram/pr-curves-n-20.png new file mode 100644 index 0000000..866b535 Binary files /dev/null and b/data/colourHistogram/pr-curves-n-20.png differ diff --git a/data/colourHistogram/pr-curves-n-4-avg.png b/data/colourHistogram/pr-curves-n-4-avg.png new file mode 100644 index 0000000..dfc29ca Binary files /dev/null and b/data/colourHistogram/pr-curves-n-4-avg.png differ diff --git a/data/colourHistogram/pr-curves-n-4.png b/data/colourHistogram/pr-curves-n-4.png new file mode 100644 index 0000000..c42edbe Binary files /dev/null and b/data/colourHistogram/pr-curves-n-4.png differ diff --git a/data/colourHistogram/pr-curves-n-5-avg.png b/data/colourHistogram/pr-curves-n-5-avg.png new file mode 100644 index 0000000..59852b2 Binary files /dev/null and b/data/colourHistogram/pr-curves-n-5-avg.png differ diff --git a/data/data.ods b/data/data.ods new file mode 100644 index 0000000..1601dab Binary files /dev/null and b/data/data.ods differ diff --git a/data/spatialColour/mapSurface1.png b/data/spatialColour/mapSurface1.png new file mode 100644 index 0000000..0167d71 Binary files /dev/null and b/data/spatialColour/mapSurface1.png differ diff --git a/data/spatialColour/mapSurface2.png b/data/spatialColour/mapSurface2.png new file mode 100644 index 0000000..b53f809 Binary files /dev/null and b/data/spatialColour/mapSurface2.png differ diff --git a/data/spatialColour/mapSurfaceWithMax.png b/data/spatialColour/mapSurfaceWithMax.png new file mode 100644 index 0000000..983fc7d Binary files /dev/null and b/data/spatialColour/mapSurfaceWithMax.png differ diff --git a/descriptor/extractGlobalColHist.m b/descriptor/extractGlobalColHist.m index 8c63086..80b6b0f 100644 --- a/descriptor/extractGlobalColHist.m +++ b/descriptor/extractGlobalColHist.m @@ -1,6 +1,6 @@ function F=extractGlobalColHist(img) -divs = 8; +divs = 5; qimg = floor(img .* divs); bin = qimg(:,:,1) * divs^2 + qimg(:,:,2) * divs^1 + qimg(:,:,3); diff --git a/descriptor/extractSpatialColour.m b/descriptor/extractSpatialColour.m index 5283644..b27a6b0 100644 --- a/descriptor/extractSpatialColour.m +++ b/descriptor/extractSpatialColour.m @@ -1,7 +1,4 @@ -function F=extractSpatialColour(img) - -grid_rows = 10; -grid_columns = 10; +function F=extractSpatialColour(img, grid_rows, grid_columns) img_size = size(img); img_rows = img_size(1); diff --git a/report/coursework.lyx b/report/coursework.lyx index 439634c..30b2f8b 100644 --- a/report/coursework.lyx +++ b/report/coursework.lyx @@ -192,10 +192,12 @@ Average colour represents one of the most basic descriptors capable of being \end_layout \begin_layout Standard -These three numbers hold no information about the distribution of colour - throughout the image and no information based on edge and shape information. - The lack of either hinders it's applicability to any real world problems. - The only advantage would be the speed of calculation. +These three numbers represent nothing about the distribution of colour throughou +t the image and nothing regarding edge and shape information. + The lack of either hinders it's practicality for real world applications + and as a result it is not used as a descriptor on it's own in this paper. + Instead average colour will be used as a sub-descriptor to form part of + a spatial colour descriptor due to it's low dimensionality. \end_layout \begin_layout Subsection @@ -329,7 +331,7 @@ Spatial Colour \end_layout \begin_layout Standard -Spatial techniques involve calculating descriptors tht are discriminative +Spatial techniques involve calculating descriptors that are discriminative between colour and shape information in different regions of the image. This is done by dividing the image into a grid of cells and then calculating individual 'sub-descriptors' which are concatenated into the global image @@ -606,9 +608,93 @@ Principal Component Analysis \end_layout \begin_layout Standard -Principal component analysis is a process to identify the variations in - a set of data. - The result is a +When extracting a descriptor from an image an important design factor is + keeping the dimensionality as low as appropriate. + This is so as to reduce the effect of the 'curse of dimensionality', a + set of adverse phenomena which arise when analysing high dimensional data. + Each additional dimension exponentially increases the volume of the feature + space, a higher dimensional descriptor requires a longer time to extract, + process and store. + Many of these dimensions will have little to no variation and so their + addition adds complexity without adding significant extra value. + +\end_layout + +\begin_layout Standard +Principal component analysis is the process of identifying the orthogonal + directions and magnitudes of variation in a dataset. + In doing so redundant, low variation dimensions can be identified and removed. + The resulting dataset has a lower dimensionality and complexity but retains + the majority of variation in the remaining dimensions. +\end_layout + +\begin_layout Standard +\begin_inset Float figure +wide false +sideways false +status open + +\begin_layout Plain Layout +\align center +\begin_inset Graphics + filename pca-example.png + lyxscale 30 + width 80col% + +\end_inset + + +\end_layout + +\begin_layout Plain Layout +\begin_inset Caption Standard + +\begin_layout Plain Layout +Visual depiction of principal 2D component analysis resulting in a new reference + frame +\begin_inset CommandInset label +LatexCommand label +name "fig:pca-visual-depiction" + +\end_inset + + +\begin_inset CommandInset citation +LatexCommand cite +key "setosa_pca" +literal "false" + +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +The process can be seen in figure +\begin_inset CommandInset ref +LatexCommand ref +reference "fig:pca-visual-depiction" +plural "false" +caps "false" +noprefix "false" + +\end_inset + +. + The left hand side shows the data presented in the root reference frame. + The right hand side shows the same data plotted in the reference frame + defined by it's own variation, in essence 'recentering' the axes around + the data. \end_layout \begin_layout Section @@ -616,21 +702,107 @@ Distance Measures \end_layout \begin_layout Standard -Once image descriptors are plotted in a feature space a visual search system - compares descriptors by measuring the distance between them. - The method for doing so will affect the ranking of descriptors. +Once image descriptors are plotted in a feature space, a visual search system + makes comparisons by measuring the distance between them. + This is calculated by finding the vector between the two points in space. + +\end_layout + +\begin_layout Standard +In mathematics the length of a vector is evaluated using a function referred + to as a norm. + Different types of norm can affect the performance of the system and therefore + different norms should be varied and measured. +\end_layout + +\begin_layout Standard +\begin_inset Float figure +wide false +sideways false +status open + +\begin_layout Plain Layout +\align center +\begin_inset Graphics + filename l2norm.jpg + lyxscale 30 + width 30col% + +\end_inset + + +\end_layout + +\begin_layout Plain Layout +\begin_inset Caption Standard + +\begin_layout Plain Layout +A single 2D cartesian co-ordinate with it's component lengths in blue and + its Euclidean magnitude in red +\begin_inset CommandInset label +LatexCommand label +name "fig:norm" + +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + \end_layout \begin_layout Subsection L1 Norm \end_layout +\begin_layout Standard +The L1 norm, or Manhattan distance, is the sum of the absolute values of + the vector. + For a 2D vector, +\begin_inset Formula $x=\left(i,j\right)$ +\end_inset + +, the L1 norm can be calculated by, +\end_layout + +\begin_layout Standard +\begin_inset Formula +\[ +\left\Vert x\right\Vert _{1}=\left|i\right|+\left|j\right| +\] + +\end_inset + + +\end_layout + +\begin_layout Standard +The L1 norm of the point defined in figure +\begin_inset CommandInset ref +LatexCommand ref +reference "fig:norm" +plural "false" +caps "false" +noprefix "false" + +\end_inset + + can be found by summing the lengths of the blue lines. +\end_layout + \begin_layout Subsection L2 Norm \end_layout \begin_layout Standard -The L2 norm, or Euclidean distance, is the shortest difference between two +The L2 norm, or Euclidean distance, is the shortest distance between two points in space, it is also referred to as the magnitude of a vector. In a three dimensional Euclidean space the magnitude of a vector, \begin_inset Formula $x=\left(i,j,k\right)$ @@ -651,8 +823,27 @@ The L2 norm, or Euclidean distance, is the shortest difference between two \end_layout \begin_layout Standard -It's intuitive distance measurement makes it the most commonly used norm - in Euclidean space. +It's intuitive +\begin_inset Quotes eld +\end_inset + +as the crow flies +\begin_inset Quotes erd +\end_inset + + distance measurement makes it the most commonly used norm in Euclidean + space. + In figure +\begin_inset CommandInset ref +LatexCommand ref +reference "fig:norm" +plural "false" +caps "false" +noprefix "false" + +\end_inset + + the length of the red line defines this points Euclidean distance. \end_layout \begin_layout Subsection @@ -786,18 +977,25 @@ While both measurements appear to reflect similar concepts there is a difference \end_layout \begin_layout Standard -A system with high recall but low precision will indicate that the system - is effectively able to retrieve all relevant documents eventually however - there will be false positives within the results. +A system with high recall but low precision at +\begin_inset Formula $n$ +\end_inset + + will indicate that the system is effectively able to retrieve all relevant + documents eventually however there will be false positives within the results. Results of this quality would be advantageous when it is important to obtain all relevant results however not when the relevance of each and every one is valued. \end_layout \begin_layout Standard -A system with high precision but low recall would indicate that the system - is able to very confident in its selection of relevant documents but may - indicate an increase in false negatives. +A system with high precision but low recall at +\begin_inset Formula $n$ +\end_inset + + would indicate that the system is able to very confident in its selection + of relevant documents but may indicate an increase in false negatives where + the system cannot correctly recognise a target image. \end_layout \begin_layout Subsection @@ -810,19 +1008,41 @@ A way to visualise the response of a visual search system is to calculate \begin_inset Formula $n$ \end_inset - and plot each pair against each for what is known as a precision-recall - curve or PR curve. + and plot each pair in a precision-recall or PR curve. +\end_layout + +\begin_layout Standard +When plotted in this fashion with recall along the +\begin_inset Formula $x$ +\end_inset + + axis and and precision along +\begin_inset Formula $y$ +\end_inset + + the curve can be thought to plot the system performance over normalised + time to retrieve the query's category set with perfect system performance + being, +\end_layout + +\begin_layout Standard +\begin_inset Formula +\[ +y=\begin{cases} +1 & 01 +\end{cases} +\] + +\end_inset + + \end_layout \begin_layout Subsection Methods \end_layout -\begin_layout Standard -In order to evaluate the performance of each descriptor two different tests - were conducted. -\end_layout - \begin_layout Subsubsection Category Response \end_layout @@ -858,17 +1078,152 @@ Results \end_layout \begin_layout Subsection -Average RGB +Global Colour Histogram \end_layout -\begin_layout Subsection -Global Colour Histogram +\begin_layout Standard +\begin_inset Float figure +wide false +sideways false +status open + +\begin_layout Plain Layout + +\end_layout + +\begin_layout Plain Layout +\align center +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/colourHistogram/pr-curves-n-5-avg.png + lyxscale 30 + width 60col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Mean precision recall curve for histogram +\begin_inset Formula $n=5$ +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\begin_inset Float figure +wide false +sideways false +status open + +\begin_layout Plain Layout + +\end_layout + +\begin_layout Plain Layout +\align center +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/colourHistogram/map-line.png + lyxscale 30 + width 80col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Mean average precision values for varying numbers of bins +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + \end_layout \begin_layout Subsection Spatial Colour \end_layout +\begin_layout Standard +\begin_inset Float figure +wide false +sideways false +status open + +\begin_layout Plain Layout +\align center +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/spatialColour/mapSurface2.png + lyxscale 40 + width 50col% + +\end_inset + + +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/spatialColour/mapSurfaceWithMax.png + lyxscale 40 + width 50col% + +\end_inset + + +\end_layout + +\begin_layout Plain Layout +\begin_inset Caption Standard + +\begin_layout Plain Layout +Mean average precision values for varying dimensions of spatial colour grid, + maximum value labelled +\begin_inset CommandInset label +LatexCommand label +name "fig:glo-col-hist-map-surfaces" + +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\end_layout + \begin_layout Subsection Spatial Colour and Texture \end_layout @@ -1344,6 +1699,1673 @@ Coast \end_inset +\end_layout + +\begin_layout Section +PR Curves +\end_layout + +\begin_layout Subsection +Global Colour Histogram, +\begin_inset Formula $n=4$ +\end_inset + + +\end_layout + +\begin_layout Standard +\align center +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/colourHistogram/pr-curves-n-4.png + lyxscale 30 + width 50col% + +\end_inset + + +\end_layout + +\begin_layout Section +Global Colour Histogram Mean Average Precision Values +\end_layout + +\begin_layout Standard +\align center +\begin_inset Tabular + + + + + + + + + + + + + + + +\begin_inset Text + +\begin_layout Plain Layout +Grid Size +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +1 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +2 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +3 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +4 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +5 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +6 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +7 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +8 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +9 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +10 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +1 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1103 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1079 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1345 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1342 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1337 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1363 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1336 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1339 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1326 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1319 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +2 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1213 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1179 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1424 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1551 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1527 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1537 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1547 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1538 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1519 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.151 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +3 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.131 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1123 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1401 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1469 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.148 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1477 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1513 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1495 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1493 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1499 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +4 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1377 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1254 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1498 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1543 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.154 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.155 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1545 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1542 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1537 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1536 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +5 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1366 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1264 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1505 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.154 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1516 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1494 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1515 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1497 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1485 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1499 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +6 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1338 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1233 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1443 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1552 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1507 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1509 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1493 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1478 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1482 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.149 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +7 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1366 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1246 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1473 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1531 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1522 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1516 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1512 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1505 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1483 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1493 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +8 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1377 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1267 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1468 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1535 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1498 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1506 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1521 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1499 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1494 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1486 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +9 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1378 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1278 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1481 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1546 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1507 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1524 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1543 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1514 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1509 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1499 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +10 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1392 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1282 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1479 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1532 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1513 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.151 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1513 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1502 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1491 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1487 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +11 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1404 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.129 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1484 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1547 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1516 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1547 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1528 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.151 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1504 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.148 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +12 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1396 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1294 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1492 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1559 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1529 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1542 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1522 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1514 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1513 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1489 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +13 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.141 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1287 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1496 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1545 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1527 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1535 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1516 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1512 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1504 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1488 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +14 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1403 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1293 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1479 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.156 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.154 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1536 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1518 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1513 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1507 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1477 +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout +15 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1413 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1312 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1494 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1557 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1515 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1503 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.15 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1489 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1495 +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +0.1464 +\end_layout + +\end_inset + + + + +\end_inset + + \end_layout \end_body diff --git a/report/l2norm.jpg b/report/l2norm.jpg new file mode 100644 index 0000000..8344f47 Binary files /dev/null and b/report/l2norm.jpg differ diff --git a/report/pca-example.png b/report/pca-example.png new file mode 100644 index 0000000..4506862 Binary files /dev/null and b/report/pca-example.png differ diff --git a/report/references.bib b/report/references.bib index bf0f200..5b09768 100644 --- a/report/references.bib +++ b/report/references.bib @@ -1 +1,3 @@ @misc{microsoft_msrc, title={Image Understanding }, url={https://www.microsoft.com/en-us/research/project/image-understanding/}, journal={Microsoft}, publisher={Microsoft}, year={2000}, month={Jan}} + +@misc{setosa_pca, title={Principal Component Analysis}, url={http://setosa.io/ev/principal-component-analysis/}, journal={Explained Visually}, publisher={Setosa}, author={Powell, Victor and Lehe, Lewis}} diff --git a/single_selected_image.m b/single_selected_image.m new file mode 100644 index 0000000..badab78 --- /dev/null +++ b/single_selected_image.m @@ -0,0 +1,280 @@ +%% 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='avgRGB'; +% DESCRIPTOR_SUBFOLDER='globalRGBhisto'; +DESCRIPTOR_SUBFOLDER='spatialColour'; +% DESCRIPTOR_SUBFOLDER='spatialColourTexture'; + +CATEGORIES = ["Farm Animal" + "Tree" + "Building" + "Plane" + "Cow" + "Face" + "Car" + "Bike" + "Sheep" + "Flower" + "Sign" + "Bird" + "Book Shelf" + "Bench" + "Cat" + "Dog" + "Road" + "Water Features" + "Human Figures" + "Coast" + ]; + +QUERY_INDEXES=[301 358 384 436 447 476 509 537 572 5 61 80 97 127 179 181 217 266 276 333]; + +% 1_10 2_16 3_12 4_4 5_15 6_14 7_17 8_15 9_1 10_14 11_8 12_26 13_10 14_10 +% 15_8 16_10 17_16 18_5 19_15 20_12 + +map = []; + +for b=1:3 + for c=1:3 + +%% 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 + +allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp'])); +for filenum=1:length(allfiles) + fname=allfiles(filenum).name; +% fprintf('Processing file %d/%d - %s\n',filenum,length(allfiles),fname); +% tic; + imgfname_full=([DATASET_FOLDER,'/Images/',fname]); + img=double(imread(imgfname_full))./255; + + %identify photo category for PR calculation + split_string = split(fname, '_'); + ALLCATs(filenum) = str2double(split_string(1)); + + %% EXTRACT FUNCTION +% F=extractAvgRGB(img); +% F=extractGlobalColHist(img); + F = extractSpatialColour(img, b, c); +% F=extractSpatialColourTexture(img); +% toc + + ALLFEAT=[ALLFEAT ; F]; +end + +% get counts for each category for PR calculation +CAT_HIST = histogram(ALLCATs).Values; +CAT_TOTAL = length(CAT_HIST); + +NIMG=size(ALLFEAT,1); % number of images in collection + +confusion_matrix = zeros(CAT_TOTAL); + +all_precision = []; +all_recall = []; + +AP_values = zeros([1, CAT_TOTAL]); +for iteration=1:CAT_TOTAL + + %% 2) Pick an image at random to be the query + queryimg=QUERY_INDEXES(iteration); % 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 + + %% 4) Calculate PR + precision_values=zeros([1, NIMG-1]); + recall_values=zeros([1, NIMG-1]); + + correct_at_n=zeros([1, NIMG-1]); + + query_row = dst(1,:); + query_category = query_row(1,3); + if query_category ~= iteration + dst + end + fprintf('category was %s\n', CATEGORIES(query_category)) + + dst = dst(2:NIMG, :); + + %calculate PR for each n + for i=1:size(dst, 1) + % NIMG-1 and j iterator variable is in order to skip calculating for query image + + rows = dst(1:i, :); + + correct_results = 0; + incorrect_results = 0; + + if i > 1 + for n=1:i - 1 + row = rows(n, :); + category = row(3); + + if category == iteration + correct_results = correct_results + 1; + else + incorrect_results = incorrect_results + 1; + end + + end + end + + % LAST ROW + row = rows(i, :); + category = row(3); + + if category == iteration + correct_results = correct_results + 1; + correct_at_n(i) = 1; + else + incorrect_results = incorrect_results + 1; + end + + precision = correct_results / i; + recall = correct_results / (CAT_HIST(1,iteration) - 1); + + precision_values(i) = precision; + recall_values(i) = recall; + end + + + %% 5) calculate AP + average_precision = sum(precision_values .* correct_at_n) / CAT_HIST(1,iteration); + AP_values(iteration) = average_precision; + + + all_precision = [all_precision ; precision_values]; + all_recall = [all_recall ; recall_values]; + + + %% 6) plot PR curve +% figure(1) +% plot(recall_values, precision_values,'LineWidth',1.5); +% hold on; +% title('Global Colour Histogram PR (n=20)'); +% xlabel('Recall'); +% ylabel('Precision'); +% xlim([0 1]); +% ylim([0 1]); + + + %% 7) 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=25; % Show top 25 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]; + + %populate confusion matrix + confusion_matrix(query_category, dst(i,3)) = confusion_matrix(query_category, dst(i,3)) + 1; + end +% figure(3) +% imgshow(outdisplay); +% axis off; + +end + +%% Plot average PR curve +% figure(4) +% mean_precision = mean(all_precision); +% mean_recall = mean(all_recall); +% plot(mean_recall, mean_precision,'LineWidth',5); +% title('Global Colour Histogram Average PR (n=20)'); +% xlabel('Average Recall'); +% ylabel('Average Precision'); +% xlim([0 1]); +% ylim([0 1]); + +% normalise confusion matrix +norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all'); + +%% 8 Calculate MAP +% figure(4) +% histogram(AP_values); +% title('Average Precision Distribution'); +% ylabel('Count'); +% xlabel('Average Precision'); +% xlim([0, 1]); + +MAP = mean(AP_values) +AP_sd = std(AP_values) + +% figure(2) +% plot(1:CAT_TOTAL, AP_values); +% title('Average Precision Per Run'); +% xlabel('Run'); +% ylabel('Average Precision'); + +fprintf('%i,%i %i', b, c, MAP); + +map(b, c) = MAP; + + end +end \ No newline at end of file