visual-search/descriptor/extractSpatialTexture.m
2019-12-01 12:25:26 +00:00

50 lines
1.3 KiB
Matlab

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;