function descriptors = do_descriptor(octave, ... % 一组的高斯尺度空间
oframes, ... % frames 包含关键点相关的尺度和主方向
sigma0, ... % 基本 sigma 值
S, ... % 该组的尺度层数
smin, ...
varargin)
for k=1:2:length(varargin)
switch lower(varargin{k})
case 'magnif'
magnif = varargin{k+1} ;
case 'numspatialbins'
NBP = varargin{k+1} ;
case 'numorientbins'
NBO = varargin{k+1} ;
otherwise
error(['Unknown parameter ' varargin{k} '.']) ;
end
end
num_spacialBins = NBP;
num_orientBins = NBO;
key_num = size(oframes, 2);
% 计算该图的向量和方向
[M, N, s_num] = size(octave); % M 是图像的高度, N 是图像的宽度; num_level is the number of scale level of the octave
descriptors = [];
magnitudes = zeros(M, N, s_num);
angles = zeros(M, N, s_num);
% compute image gradients
for si = 1: s_num
img = octave(:,:,si);
dx_filter = [-0.5 0 0.5];
dy_filter = dx_filter';
gradient_x = imfilter(img, dx_filter);
gradient_y = imfilter(img, dy_filter);
magnitudes(:,:,si) =sqrt( gradient_x.^2 + gradient_y.^2);
% if sum( gradient_x == 0) > 0
% fprintf('00');
% end
angles(:,:,si) = mod(atan(gradient_y ./ (eps + gradient_x)) + 2*pi, 2*pi);
end
x = oframes(1,:);
y = oframes(2,:);
s = oframes(3,:);
% round off
x_round = floor(oframes(1,:) + 0.5);
y_round = floor(oframes(2,:) + 0.5);
scales = floor(oframes(3,:) + 0.5) - smin;
for p = 1: key_num %对各个关键点处理
s = scales(p);
xp= x_round(p);
yp= y_round(p);
theta0 = oframes(4,p);%关键点的主方向
sinth0 = sin(theta0) ;
costh0 = cos(theta0) ;
sigma = sigma0 * 2^(double (s / S)) ;
SBP = magnif * sigma;
%W = floor( sqrt(2.0) * SBP * (NBP + 1) / 2.0 + 0.5);
W = floor( 0.8 * SBP * (NBP + 1) / 2.0 + 0.5);
descriptor = zeros(NBP, NBP, NBO);
% within the big square, select the pixels with the circle and put into
% the histogram. no need to do rotation which is very expensive
%在大正方形中用高斯加权圆选择像素点放入方向直方图中,不需要做昂贵的图像旋转
for dxi = max(-W, 1-xp): min(W, N -2 - xp)
for dyi = max(-W, 1-yp) : min(+W, M-2-yp)
mag = magnitudes(yp + dyi, xp + dxi, s); % 当前点(yp + dyi, xp + dxi)的梯度幅值
angle = angles(yp + dyi, xp + dxi, s) ; % 当前点(yp + dyi, xp + dxi)的梯度幅角
% angle = mod(-angle + theta0, 2*pi); % 用关键点的主方向调整角度 并且 mod it with 2*pi
angle = mod(angle - theta0, 2*pi);
dx = double(xp + dxi - x(p)); % x(p) 是关键点的精确位置 (浮点数). dx 相对于该关键点当前像素的位置
dy = double(yp + dyi - y(p)); % dy 相对于该关键点当前像素的位置
nx = ( costh0 * dx + sinth0 * dy) / SBP ; % nx 是旋转(dx, dy)后的规格化位置 with the major orientation angle. this tells which x-axis spatial bin the pixel falls in
ny = (-sinth0 * dx + costh0 * dy) / SBP ;
nt = NBO * angle / (2* pi) ;
wsigma = NBP/2 ;
wincoef = exp(-(nx*nx + ny*ny)/(2.0 * wsigma * wsigma)) ;
binx = floor( nx - 0.5 ) ;
biny = floor( ny - 0.5 ) ;
bint = floor( nt );
rbinx = nx - (binx+0.5) ;
rbiny = ny - (biny+0.5) ;
rbint = nt - bint ;
for(dbinx = 0:1)
for(dbiny = 0:1)
for(dbint = 0:1)
% if condition limits the samples within the square
% width W. binx+dbinx is the rotated x-coordinate.
% therefore the sampling square is effectively a
% rotated one
%如果条件限制在用宽度W设定的方形内的样点,binx+dbinx是旋转后的x坐标
%因此采样方形的旋转是有效的。
if( binx+dbinx >= -(NBP/2) && ...
binx+dbinx < (NBP/2) && ...
biny+dbiny >= -(NBP/2) && ...
biny+dbiny < (NBP/2) && isnan(bint) == 0)
weight = wincoef * mag * abs(1 - dbinx - rbinx) ...
* abs(1 - dbiny - rbiny) ...
* abs(1 - dbint - rbint) ;
descriptor(binx+dbinx + NBP/2 + 1, biny+dbiny + NBP/2+ 1, mod((bint+dbint),NBO)+1) = ...
descriptor(binx+dbinx + NBP/2+ 1, biny+dbiny + NBP/2+ 1, mod((bint+dbint),NBO)+1 ) + weight ;
end
end
end
end
end
end
descriptor = reshape(descriptor, 1, NBP * NBP * NBO);%用一维向量表示各梯度值
descriptor = descriptor ./ norm(descriptor); %归一化处理梯度值
%Truncate at 0.2
indx = find(descriptor > 0.2);%找出幅值大于0.2的梯度值
descriptor(indx) = 0.2; %大于0.2的梯度值直接取0.2
descriptor = descriptor ./ norm(descriptor); %再次归一化梯度值
descriptors = [descriptors, descriptor'];
end
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.版本:matlab2021a,包含仿真操作录像,操作录像使用windows media player播放。 2.领域:SIFT特征提取和配准 3.内容:图像的SIFT特征提取和配准MATLAB仿真。 [frames1,descr1,gss1,dogss1] = do_sift( I1, 'Verbosity', 1, 'NumOctaves', 4, 'Threshold', 0.1/3/2 ) ; %0.04/3/2 [frames2,descr2,gss2,dogss2] = do_sift( I2, 'Verbosity', 1, 'NumOctaves', 4, 'Threshold', 0.1/3/2 ) ; 4.注意事项:注意MATLAB左侧当前文件夹路径,必须是程序所在文件夹位置,具体可以参考视频录。
资源推荐
资源详情
资源评论
收起资源包目录
图像的SIFT特征提取和配准MATLAB仿真.rar (27个子文件)
2.jpg 32KB
MATLAB实现图像的SIFT特征提取源码程序
demo_1.m 887B
demo_2.m 872B
demo-data
view01.png 565KB
image068.JPG 14KB
beaver13.bmp 186KB
image069.JPG 13KB
beaver11.bmp 186KB
view02.png 561KB
demo_3.m 888B
func
do_diffofg.m 464B
do_gaussian.m 3KB
appendimages.m 359B
plotsiftframe.m 2KB
tightsubplot.m 2KB
do_orientation.m 2KB
do_match.m 5KB
imreadbw.m 301B
smooth.m 215B
do_extrefine.m 4KB
plotss.m 640B
do_sift.m 4KB
do_descriptor.m 5KB
do_localmax.m 2KB
1.jpg 27KB
操作录像0042.avi 6.48MB
3.jpg 18KB
共 27 条
- 1
资源评论
- wujlyl2022-11-10这个资源对我启发很大,受益匪浅,学到了很多,谢谢分享~
- hanguoshifoujianfeng2023-01-17资源很赞,希望多一些这类资源。
- fornayuki2024-05-02资源很赞,希望多一些这类资源。
fpga和matlab
- 粉丝: 16w+
- 资源: 2553
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 120 240 VAC_ASD-4D5 -ASD-006.IGS
- WinCHM.exe CHM 文档编辑器
- FileGeeCNP.exe
- record record record record record record record record record
- Android 启动提示Android 正在升级...提示源码分析
- pojie-drawio-confluence-plugin-9.5.8.obr
- 信息学奥赛2020年NOIP真题
- SunloginClient-15.1.0.58718-x64.exe
- 信息学奥赛2021年NOIP真题
- 星辰语义大模型TeleChat超详细部署文档手册
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功