diff --git a/cvpr_computedescriptors.m b/cvpr_computedescriptors.m index 2f765b8..a0af5d6 100644 --- a/cvpr_computedescriptors.m +++ b/cvpr_computedescriptors.m @@ -25,6 +25,7 @@ OUT_FOLDER = 'descriptors'; % OUT_SUBFOLDER='avgRGB'; OUT_SUBFOLDER='globalRGBhisto'; % OUT_SUBFOLDER='spatialColour'; +% DESCRIPTOR_SUBFOLDER='spatialTexture'; % OUT_SUBFOLDER='spatialColourTexture'; allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp'])); @@ -38,8 +39,9 @@ for filenum=1:length(allfiles) %% EXTRACT FUNCTION % F=extractAvgRGB(img); - F=extractGlobalColHist(img); + F=extractGlobalColHist(img, 2, 1, 8, 0.05); % F=extractSpatialColour(img, 2, 1); +% F=extractSpatialTexture(img, 2, 1, 8, 0.05); % F=extractSpatialColourTexture(img); save(fout,'F'); toc diff --git a/cvpr_visualsearch_pca_image.m b/cvpr_visualsearch_pca_image.m index 1bde2a3..22f0754 100644 --- a/cvpr_visualsearch_pca_image.m +++ b/cvpr_visualsearch_pca_image.m @@ -30,6 +30,7 @@ DESCRIPTOR_FOLDER = 'descriptors'; % DESCRIPTOR_SUBFOLDER='avgRGB'; DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='spatialColour'; +% DESCRIPTOR_SUBFOLDER='spatialTexture'; % DESCRIPTOR_SUBFOLDER='spatialColourTexture'; CATEGORIES = ["Farm Animal" diff --git a/cvpr_visualsearch_rand_image.m b/cvpr_visualsearch_rand_image.m index 37bd61c..193aaf6 100644 --- a/cvpr_visualsearch_rand_image.m +++ b/cvpr_visualsearch_rand_image.m @@ -30,6 +30,7 @@ DESCRIPTOR_FOLDER = 'descriptors'; DESCRIPTOR_SUBFOLDER='avgRGB'; % DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='spatialColour'; +% DESCRIPTOR_SUBFOLDER='spatialTexture'; % DESCRIPTOR_SUBFOLDER='spatialColourTexture'; CATEGORIES = ["Farm Animal" diff --git a/cvpr_visualsearch_selected_image.m b/cvpr_visualsearch_selected_image.m index 9ccafb9..0801102 100644 --- a/cvpr_visualsearch_selected_image.m +++ b/cvpr_visualsearch_selected_image.m @@ -30,6 +30,7 @@ DESCRIPTOR_FOLDER = 'descriptors'; % DESCRIPTOR_SUBFOLDER='avgRGB'; DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='spatialColour'; +% DESCRIPTOR_SUBFOLDER='spatialTexture'; % DESCRIPTOR_SUBFOLDER='spatialColourTexture'; CATEGORIES = ["Farm Animal" diff --git a/data/colourHistogram/map-line.png b/data/colourHistogram/map-line.png index ba84ea7..c218b04 100644 Binary files a/data/colourHistogram/map-line.png and b/data/colourHistogram/map-line.png differ diff --git a/data/data.ods b/data/data.ods index 1601dab..60956a3 100644 Binary files a/data/data.ods and b/data/data.ods differ diff --git a/data/edgeThresholds/10_14_flower_edge.png b/data/edgeThresholds/10_14_flower_edge.png new file mode 100644 index 0000000..6730c33 Binary files /dev/null and b/data/edgeThresholds/10_14_flower_edge.png differ diff --git a/data/edgeThresholds/10_14_s.png b/data/edgeThresholds/10_14_s.png new file mode 100644 index 0000000..a5c78f0 Binary files /dev/null and b/data/edgeThresholds/10_14_s.png differ diff --git a/data/edgeThresholds/5_15_cow_edge.png b/data/edgeThresholds/5_15_cow_edge.png new file mode 100644 index 0000000..3a07fa4 Binary files /dev/null and b/data/edgeThresholds/5_15_cow_edge.png differ diff --git a/data/edgeThresholds/5_15_s.png b/data/edgeThresholds/5_15_s.png new file mode 100644 index 0000000..0ed14df Binary files /dev/null and b/data/edgeThresholds/5_15_s.png differ diff --git a/data/edgeThresholds/cow-t-0.01.png b/data/edgeThresholds/cow-t-0.01.png new file mode 100644 index 0000000..921a773 Binary files /dev/null and b/data/edgeThresholds/cow-t-0.01.png differ diff --git a/data/edgeThresholds/cow-t-0.05.png b/data/edgeThresholds/cow-t-0.05.png new file mode 100644 index 0000000..e8d799f Binary files /dev/null and b/data/edgeThresholds/cow-t-0.05.png differ diff --git a/data/edgeThresholds/cow-t-0.08.png b/data/edgeThresholds/cow-t-0.08.png new file mode 100644 index 0000000..b531bac Binary files /dev/null and b/data/edgeThresholds/cow-t-0.08.png differ diff --git a/data/edgeThresholds/cow-t-0.1.png b/data/edgeThresholds/cow-t-0.1.png new file mode 100644 index 0000000..c74de39 Binary files /dev/null and b/data/edgeThresholds/cow-t-0.1.png differ diff --git a/data/edgeThresholds/cow-t-0.2.png b/data/edgeThresholds/cow-t-0.2.png new file mode 100644 index 0000000..3a4e573 Binary files /dev/null and b/data/edgeThresholds/cow-t-0.2.png differ diff --git a/data/edgeThresholds/flower-t-0.005.png b/data/edgeThresholds/flower-t-0.005.png new file mode 100644 index 0000000..43a4698 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.005.png differ diff --git a/data/edgeThresholds/flower-t-0.01.png b/data/edgeThresholds/flower-t-0.01.png new file mode 100644 index 0000000..07b9f05 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.01.png differ diff --git a/data/edgeThresholds/flower-t-0.02.png b/data/edgeThresholds/flower-t-0.02.png new file mode 100644 index 0000000..425a4a6 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.02.png differ diff --git a/data/edgeThresholds/flower-t-0.05.png b/data/edgeThresholds/flower-t-0.05.png new file mode 100644 index 0000000..78dd397 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.05.png differ diff --git a/data/edgeThresholds/flower-t-0.08.png b/data/edgeThresholds/flower-t-0.08.png new file mode 100644 index 0000000..3a84a16 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.08.png differ diff --git a/data/edgeThresholds/flower-t-0.1.png b/data/edgeThresholds/flower-t-0.1.png new file mode 100644 index 0000000..17d8fb7 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.1.png differ diff --git a/data/edgeThresholds/flower-t-0.2.png b/data/edgeThresholds/flower-t-0.2.png new file mode 100644 index 0000000..bef3f36 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.2.png differ diff --git a/data/edgeThresholds/flower-t-0.3.png b/data/edgeThresholds/flower-t-0.3.png new file mode 100644 index 0000000..5d50bf2 Binary files /dev/null and b/data/edgeThresholds/flower-t-0.3.png differ diff --git a/data/spatialTexture/map-bin-vary.png b/data/spatialTexture/map-bin-vary.png new file mode 100644 index 0000000..1192fd3 Binary files /dev/null and b/data/spatialTexture/map-bin-vary.png differ diff --git a/descriptor/extractSpatialColourTexture.m b/descriptor/extractSpatialColourTexture.m index 4f92f83..1bf1c83 100644 --- a/descriptor/extractSpatialColourTexture.m +++ b/descriptor/extractSpatialColourTexture.m @@ -1,7 +1,4 @@ -function F=extractSpatialColourTexture(img) - -grid_rows = 8; -grid_columns = 8; +function F=extractSpatialColourTexture(img, grid_rows, grid_columns, bins, threshold) img_size = size(img); img_rows = img_size(1); @@ -43,7 +40,7 @@ for i = 1:grid_rows avg_vals = extractAvgRGB(img_cell); [mag_img, angle_img] = getEdgeInfo(grey_img_cell); - edge_hist = getEdgeAngleHist(mag_img, angle_img, 8, 0.05); + edge_hist = getEdgeAngleHist(mag_img, angle_img, bins, threshold); %concatenate average values into vector descriptor = [descriptor edge_hist avg_vals(1) avg_vals(2) avg_vals(3)]; diff --git a/descriptor/extractSpatialTexture.m b/descriptor/extractSpatialTexture.m new file mode 100644 index 0000000..8581172 --- /dev/null +++ b/descriptor/extractSpatialTexture.m @@ -0,0 +1,50 @@ +function F=extractSpatialTexture(img, grid_rows, grid_columns, bins, threshold) + +img_size = size(img); +img_rows = img_size(1); +img_cols = img_size(2); + +row_divs = []; +for i = 1:grid_rows + row_divs(i) = i/grid_rows; +end +col_divs = []; +for i = 1:grid_columns + col_divs(i) = i/grid_columns; +end + +descriptor = []; +%% divide image into sectors as defined grid parameters +for i = 1:grid_rows + for j = 1:grid_columns + + % cell row pixel range + row_start = round( (i-1)*img_rows/grid_rows ); + if row_start == 0 + row_start = 1; + end + row_end = round( i*img_rows/grid_rows ); + + % cell column pixel range + col_start = round( (j-1)*img_cols/grid_columns ); + if col_start == 0 + col_start = 1; + end + col_end = round( j*img_cols/grid_columns ); + + % grab cell from parameters as above + img_cell = img(row_start:row_end, col_start:col_end, :); + grey_img_cell = getGreyscale(img_cell); + + [mag_img, angle_img] = getEdgeInfo(grey_img_cell); + + edge_hist = getEdgeAngleHist(mag_img, angle_img, bins, threshold); + + %concatenate average values into vector + descriptor = [descriptor edge_hist]; + + end +end + +F=descriptor; +return; \ No newline at end of file diff --git a/single_selected_image.m b/parameter_iter_selected_image.m similarity index 85% rename from single_selected_image.m rename to parameter_iter_selected_image.m index badab78..fc040bf 100644 --- a/single_selected_image.m +++ b/parameter_iter_selected_image.m @@ -61,8 +61,10 @@ QUERY_INDEXES=[301 358 384 436 447 476 509 537 572 5 61 80 97 127 179 181 217 26 map = []; -for b=1:3 - for c=1:3 +thresholded = [0.01:0.01:0.15]; + +for b=1:15 +% for c=1:10 %% 1) Load all the descriptors into "ALLFEAT" %% each row of ALLFEAT is a descriptor (is an image) @@ -71,23 +73,6 @@ 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) @@ -104,8 +89,9 @@ for filenum=1:length(allfiles) %% EXTRACT FUNCTION % F=extractAvgRGB(img); % F=extractGlobalColHist(img); - F = extractSpatialColour(img, b, c); -% F=extractSpatialColourTexture(img); +% F = extractSpatialColour(img, b, c); + F=extractSpatialTexture(img, 4, 4, 7, thresholded(1,b)); +% F=extractSpatialColourTexture(img, b, c, 8, 0.08); % toc ALLFEAT=[ALLFEAT ; F]; @@ -150,9 +136,9 @@ for iteration=1:CAT_TOTAL query_row = dst(1,:); query_category = query_row(1,3); - if query_category ~= iteration - dst - end +% if query_category ~= iteration +% dst +% end fprintf('category was %s\n', CATEGORIES(query_category)) dst = dst(2:NIMG, :); @@ -272,9 +258,11 @@ AP_sd = std(AP_values) % xlabel('Run'); % ylabel('Average Precision'); -fprintf('%i,%i %i', b, c, MAP); +% fprintf('%i,%i %i', b, c, MAP); +fprintf('%i,%i', b, MAP); -map(b, c) = MAP; +% map(b, c) = MAP; +map(b) = MAP; - end +% end end \ No newline at end of file diff --git a/report/coursework.lyx b/report/coursework.lyx index 30b2f8b..4de13bc 100644 --- a/report/coursework.lyx +++ b/report/coursework.lyx @@ -1123,9 +1123,6 @@ Mean precision recall curve for histogram \end_inset -\end_layout - -\begin_layout Standard \begin_inset Float figure wide false sideways false @@ -1179,7 +1176,7 @@ status open \align center \begin_inset Graphics filename /home/andy/dev/matlab/cv-coursework/data/spatialColour/mapSurface2.png - lyxscale 40 + lyxscale 20 width 50col% \end_inset @@ -1187,7 +1184,7 @@ status open \begin_inset Graphics filename /home/andy/dev/matlab/cv-coursework/data/spatialColour/mapSurfaceWithMax.png - lyxscale 40 + lyxscale 20 width 50col% \end_inset @@ -1222,12 +1219,279 @@ name "fig:glo-col-hist-map-surfaces" \end_inset +\end_layout + +\begin_layout Subsection +Spatial Texture +\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/edgeThresholds/10_14_s.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset space \quad{} +\end_inset + + +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/edgeThresholds/10_14_flower_edge.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Image 10_14_s from the flower category followed by visualisation of detected + edges +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\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/edgeThresholds/5_15_s.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset space \quad{} +\end_inset + + +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/edgeThresholds/5_15_cow_edge.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Image 5_15_s from the cow category followed by visualisation of detected + edges +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\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/edgeThresholds/flower-t-0.01.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset space \quad{} +\end_inset + + +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/edgeThresholds/cow-t-0.01.png + lyxscale 30 + width 20col% + +\end_inset + + +\end_layout + +\begin_layout Plain Layout +\begin_inset Caption Standard + +\begin_layout Plain Layout +Angle magnitude images after threshold = 0.01 +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\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/edgeThresholds/flower-t-0.08.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset space \quad{} +\end_inset + + +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/edgeThresholds/cow-t-0.08.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Angle magnitude images after threshold = 0.08 +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\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/edgeThresholds/flower-t-0.2.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset space \quad{} +\end_inset + + +\begin_inset Graphics + filename /home/andy/dev/matlab/cv-coursework/data/edgeThresholds/cow-t-0.2.png + lyxscale 30 + width 20col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Angle magnitude images after threshold = 0.2 +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\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/spatialTexture/map-bin-vary.png + lyxscale 30 + width 80col% + +\end_inset + + +\begin_inset Caption Standard + +\begin_layout Plain Layout +Mean average precision values for varying numbers of bins, grid size 4x4, + threshold 0.08 +\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 +\begin_layout Subsection +Principal Component Analysis +\end_layout + \begin_layout Section Discussion \end_layout diff --git a/scratch.m b/scratch.m index 9598b5f..a99531c 100644 --- a/scratch.m +++ b/scratch.m @@ -1,2 +1,10 @@ -loadDescriptors() \ No newline at end of file +img = double(imread('dataset/Images/5_15_s.bmp'))./255; + +img = getGreyscale(img); + +[mag_img, angle_img] = getEdgeInfo(img); + +imshow(mag_img > 0.01); + +export_fig(mag_img > 0.01); \ No newline at end of file