added edge extraction, added spatial colour texture descriptor
This commit is contained in:
parent
1393656203
commit
5a83879c78
@ -23,7 +23,9 @@ OUT_FOLDER = '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='globalRGBhisto';
|
||||
% OUT_SUBFOLDER='spatialColour';
|
||||
OUT_SUBFOLDER='spatialColourTexture';
|
||||
|
||||
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
|
||||
for filenum=1:length(allfiles)
|
||||
@ -36,7 +38,9 @@ for filenum=1:length(allfiles)
|
||||
|
||||
%% EXTRACT FUNCTION
|
||||
% F=extractAvgRGB(img);
|
||||
F=extractGlobalColHist(img);
|
||||
% F=extractGlobalColHist(img);
|
||||
% F=extractSpatialColour(img);
|
||||
F=extractSpatialColourTexture(img);
|
||||
save(fout,'F');
|
||||
toc
|
||||
end
|
||||
|
@ -28,7 +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';
|
||||
|
||||
|
||||
%% 1) Load all the descriptors into "ALLFEAT"
|
||||
@ -59,7 +61,7 @@ end
|
||||
% get counts for each category for PR calculation
|
||||
CAT_HIST = histogram(ALLCATs).Values;
|
||||
|
||||
run_total = 20;
|
||||
run_total = 100;
|
||||
AP_values = zeros([1, run_total]);
|
||||
for run=1:run_total
|
||||
%% 2) Pick an image at random to be the query
|
||||
@ -81,7 +83,7 @@ for run=1:run_total
|
||||
end
|
||||
dst=sortrows(dst,1); % sort the results
|
||||
|
||||
%% 3.5) Calculate PR
|
||||
%% 4) Calculate PR
|
||||
precision_values=zeros([1, NIMG]);
|
||||
recall_values=zeros([1, NIMG]);
|
||||
|
||||
@ -89,6 +91,8 @@ for run=1:run_total
|
||||
|
||||
query_row = dst(1,:);
|
||||
query_category = query_row(1,3);
|
||||
|
||||
%calculate PR for each n
|
||||
for i=1:NIMG
|
||||
|
||||
rows = dst(1:i, :);
|
||||
@ -129,7 +133,7 @@ for run=1:run_total
|
||||
end
|
||||
|
||||
|
||||
%% 3.6) calculate AP
|
||||
%% 5) calculate AP
|
||||
P_rel_n = zeros([1, NIMG]);
|
||||
for i = 1:NIMG
|
||||
precision = precision_values(i);
|
||||
@ -144,7 +148,8 @@ for run=1:run_total
|
||||
AP_values(run) = average_precision;
|
||||
|
||||
|
||||
%% 3.8) plot PR curve
|
||||
|
||||
%% 6) plot PR curve
|
||||
figure(1)
|
||||
plot(recall_values, precision_values);
|
||||
hold on;
|
||||
@ -154,12 +159,18 @@ for run=1:run_total
|
||||
|
||||
end
|
||||
|
||||
%% 3.9 Calculate MAP
|
||||
%% 7 Calculate MAP
|
||||
AP_values
|
||||
MAP = mean(AP_values)
|
||||
|
||||
figure(2)
|
||||
plot(1:run_total, AP_values);
|
||||
title('Average Precision Per Run');
|
||||
xlabel('Run');
|
||||
ylabel('Average Precision');
|
||||
|
||||
%% 4) Visualise the results
|
||||
|
||||
%% 8) Visualise the results
|
||||
%% These may be a little hard to see using imgshow
|
||||
%% If you have access, try using imshow(outdisplay) or imagesc(outdisplay)
|
||||
|
||||
@ -172,6 +183,6 @@ for i=1:size(dst,1)
|
||||
img=img(1:81,:,:); % crop image to uniform size vertically (some MSVC images are different heights)
|
||||
outdisplay=[outdisplay img];
|
||||
end
|
||||
figure(2)
|
||||
figure(3)
|
||||
imgshow(outdisplay);
|
||||
axis off;
|
||||
|
51
descriptor/extractSpatialColour.m
Normal file
51
descriptor/extractSpatialColour.m
Normal file
@ -0,0 +1,51 @@
|
||||
function F=extractSpatialColour(img)
|
||||
|
||||
grid_rows = 10;
|
||||
grid_columns = 10;
|
||||
|
||||
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, :);
|
||||
|
||||
%take average values
|
||||
avg_vals = extractAvgRGB(img_cell);
|
||||
|
||||
%concatenate average values into vector
|
||||
descriptor = [descriptor avg_vals(1) avg_vals(2) avg_vals(3)];
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
F=descriptor;
|
||||
return;
|
55
descriptor/extractSpatialColourTexture.m
Normal file
55
descriptor/extractSpatialColourTexture.m
Normal file
@ -0,0 +1,55 @@
|
||||
function F=extractSpatialColourTexture(img)
|
||||
|
||||
grid_rows = 10;
|
||||
grid_columns = 10;
|
||||
|
||||
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);
|
||||
|
||||
%take average values
|
||||
avg_vals = extractAvgRGB(img_cell);
|
||||
[mag_img, angle_img] = getEdgeInfo(grey_img_cell);
|
||||
|
||||
edge_hist = getEdgeAngleHist(mag_img, angle_img);
|
||||
|
||||
%concatenate average values into vector
|
||||
descriptor = [descriptor edge_hist avg_vals(1) avg_vals(2) avg_vals(3)];
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
F=descriptor;
|
||||
return;
|
6
distance/compareL1.m
Normal file
6
distance/compareL1.m
Normal file
@ -0,0 +1,6 @@
|
||||
function dst=compareL1(F1, F2)
|
||||
|
||||
x=F1-F2;
|
||||
dst=sum(x);
|
||||
|
||||
return;
|
@ -1,8 +1,10 @@
|
||||
|
||||
|
||||
img = double(imread('dataset/Images/10_10_s.bmp'))./255;
|
||||
imshow(img);
|
||||
% imshow(img);
|
||||
|
||||
img = getGreyscale(img);
|
||||
|
||||
glo = extractGlobalColHist(img);
|
||||
size(img);
|
||||
[mag, angle] = getEdgeInfo(img);
|
||||
|
||||
F = getEdgeAngleHist(mag, angle)
|
||||
|
25
util/getEdgeAngleHist.m
Normal file
25
util/getEdgeAngleHist.m
Normal file
@ -0,0 +1,25 @@
|
||||
function F=getEdgeAngleHist(mag_img, angle_img)
|
||||
|
||||
bins = 8;
|
||||
threshold = 0.1;
|
||||
|
||||
dimensions = size(angle_img);
|
||||
rows = dimensions(1);
|
||||
columns = dimensions(2);
|
||||
|
||||
vals = [];
|
||||
for i = 1:rows
|
||||
for j = 1:columns
|
||||
if mag_img(i, j) > threshold
|
||||
|
||||
bin_value = angle_img(i, j) / (2 * pi);
|
||||
bin_value = bin_value * bins;
|
||||
|
||||
vals = [vals bin_value];
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
F= histogram(vals, bins, 'Normalization', 'probability').Values;
|
||||
return;
|
18
util/getEdgeInfo.m
Normal file
18
util/getEdgeInfo.m
Normal file
@ -0,0 +1,18 @@
|
||||
function [mag_img, angle_img]=getEdgeInfo(img)
|
||||
|
||||
blur = [1 1 1 ; 1 1 1 ; 1 1 1] ./ 9;
|
||||
blurredimg = conv2(img, blur, 'same');
|
||||
|
||||
Kx = [1 2 1 ; 0 0 0 ; -1 -2 -1] ./ 4;
|
||||
Ky = Kx';
|
||||
|
||||
dx = conv2(blurredimg, Kx, 'same');
|
||||
dy = conv2(blurredimg, Ky, 'same');
|
||||
|
||||
mag_img = sqrt(dx.^2 + dy.^2);
|
||||
angle_img = atan2(dy,dx);
|
||||
|
||||
% normalise between 0 and 2pi
|
||||
angle_img = angle_img - min(reshape(angle_img, 1, []));
|
||||
|
||||
return;
|
5
util/getGreyscale.m
Normal file
5
util/getGreyscale.m
Normal file
@ -0,0 +1,5 @@
|
||||
function gryimg=getGreyscale(img)
|
||||
|
||||
gryimg = img(:,:,1) * 0.3 + img(:,:,2) * 0.59 + img(:,:,3) * 0.11;
|
||||
|
||||
return;
|
Loading…
Reference in New Issue
Block a user