资源简介
FAST算法原理:若某像素与其周围邻域内足够多的像素点相差较大,则该点可能是角点。用FAST算法检测角点,代替差分高斯金字塔取极值检测角点的方法,速度块;接着用SIFT特征描述符描述角点,省略尺度空间值,只用原图像中角点邻域的梯度值和方向计算角点主方向,接着计算32个方向向量来描述角点。之和可用于特征点匹配。
代码片段和文件信息
%sift算法的描述符
%计算主方向
%在特征点的一个区域内计算梯度直方图(分36个角度)
%特征描述是32维
function [desc locs ]=features_description(fim_features)
f = mat2gray(rgb2gray(im2double(f)));
g = gaussian_filter( 1.5 * 2 ); % 9
zero_pad = ceil( length(g) / 2 ); % 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1)计算梯度方向和幅值
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf( ‘Computing gradient magnitude and orientation...\n‘ );
tic;
diff_x = 0.5*(f(2:(end-1)3:(end))-f(2:(end-1)1:(end-2))); %L(x+1y)-L(x-1y)
diff_y = 0.5*(f(3:(end)2:(end-1))-f(1:(end-2)2:(end-1))); %L(xy+1)-L(xy-1)
mag = zeros(size(f));
mag(2:(end-1)2:(end-1)) = sqrt( diff_x .^ 2 + diff_y .^ 2 );%梯度幅值
mag_pad = zeros(size(mag)+2*zero_pad);
mag_pad((zero_pad+1):(end-zero_pad)(zero_pad+1):(end-zero_pad)) = mag;
grad = zeros(size(f));
grad(2:(end-1)2:(end-1)) = atan2( diff_y diff_x ); %梯度方向
grad(grad == pi) = -pi;
grad_pad = zeros(size(grad)+2*zero_pad);
grad_pad((zero_pad+1):(end-zero_pad)(zero_pad+1):(end-zero_pad)) = grad;
clear mag grad
grad_time = toc;
fprintf( ‘Gradient calculation time %.2f seconds.\n‘ grad_time );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2)确定特征点的主方向:将特征点周围邻域的梯度方向列直方图(36个方向),寻找极大值,同时超过极大值80%的方向为辅方向
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf( ‘Assigining keypoint orientations...\n‘ );
num_bins = 36;
hist_step = 2*pi/num_bins; % 10“c
hist_orient = [-pi:hist_step:(pi-hist_step)];% -180:10:170
pos = []; % 初始化关键点的位置、方向及尺度信息
orient = [];
scale = [];
tic;
keypoint_count = 0;
% 构造高斯加权掩膜
g = gaussian_filter( 1.5 * 2 ); % sigma=3 n=5
hf_sz = floor(length(g)/2);% 取比length(g)/2小的最大整数
g = g‘*g;
loc_pad = zeros(size(f)+2*zero_pad);
loc_pad((zero_pad+1):(end-zero_pad)(zero_pad+1):(end-zero_pad)) = im_features;
[iy ix]=find(loc_pad==1); %ix是图像的行,iy是图像的列
for k = 1:length(iy)
x = ix(k);
y = iy(k);
wght = g.*mag_pad((y-hf_sz):(y+hf_sz)(x-hf_sz):(x+hf_sz));%加权极值点的邻域,length(g)Xlength(g)
grad_window = grad_pad((y-hf_sz):(y+hf_sz)(x-hf_sz):(x+hf_sz));% 选取邻域的角度
orient_hist=zeros(length(hist_orient)1);% 36X1
for bin=1:length(hist_orient)% 1 : 36
diff = mod( grad_window - hist_orient(bin) + pi 2*pi ) - pi;
%绝对值小于10度;或大于10度
orient_hist(bin)=orient_hist(bin)+sum(sum(wght.*max(1 - abs(diff)/hist_step0)));
end
% 用非极大值抑制法找到直方图的极值
peaks = orient_hist;
rot_right = [ peaks(end); peaks(1:end-1) ]; % 1-D array with 36 elements
rot_left = [ peaks(2:end); peaks(1) ]; % 1-D array with 36 elements
peaks(peaks < rot_right) = 0;
peaks(peaks < rot_left) = 0;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8444 2017-09-05 10:49 fast+sift\features_desc
文件 2468 2017-09-05 10:36 fast+sift\features_get.m
文件 259 2017-08-24 09:21 fast+sift\gaussian_filter.m
文件 37568 2017-07-17 18:02 fast+sift\haibao.jpg
文件 1872 2017-09-05 09:12 fast+sift\showkeys.m
文件 90 2017-09-05 10:51 fast+sift\test.m
目录 0 2017-09-05 11:05 fast+sift
----------- --------- ---------- ----- ----
50701 7
评论
共有 条评论