matlab特征匹配部分程序整理
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Affine
function img2 = affine(img, r, sx, sy, a, b, xo, yo)
R = [cos(r) -sin(r) 0;
sin(r) cos(r) 0;
0 0 1];
S = [sx a 0;
b sy 0;
0 0 1];
T2 = [1 0 -xo;
0 1 -yo;
0 0 1];
T1 = [1 0 xo;
0 1 yo;
0 0 1];
A = T1*R*S*T2;
[h,w]=size(img);
[x,y] = meshgrid(1:h,1:w);
x=x(:);
y=y(:);
XP = [x';y';ones(1,length(x))];
X = A*XP;
z = find(X(1,:)>w-1);
X(1,z) = w-1;
z = find(X(1,:)<=1);
X(1,z) = 1.5;
z= find(X(2,:)>h-1);
X(2,z) = h-1;
z= find(X(2,:)<1.5);
X(2,z) = 1.5;
x = X(1,:);
y = X(2,:);
alpha = x - floor(x); %calculate alphas and betas for each point
beta = y - floor(y);
fx = floor(x); fy = floor(y);
inw = fy + (fx-1)*h; %create index(索引)for neighboring pixels ine = fy + fx*h;
isw = fy+1 + (fx-1)*h;
ise = fy+1 + fx*h;
img2 = (1-alpha).*(1-beta).*img(inw) + ... %interpolate(同样)(1-alpha).*beta.*img(isw) + ...
alpha.*(1-beta).*img(ine) + ...
alpha.*beta.*img(ise);
img2 = reshape(img2,h,w);
imagesc(img2);
%build_pyramid
function [pyr,imp] = build_pyramid(img,levels,scl)
img2 = img;
img2 = resample_bilinear(img2,1/2); %expand to retain spatial frequencies %img2 = imresize(img2,2,'bilinear'); %expand to retain spatial frequencies sigma=1.5; %variance for laplacian filter
sigma2=1.5; %variance for downsampling
sig_delta = (1.6-.6)/levels;
for i=1:levels
if i==1
img3 = img2;
img2 = filter_gaussian(img2,7,.5); %slightly filter bottom level end
imp{i}=img2;
A = filter_gaussian(img2,7,sigma); %calculate difference of gaussians
B = filter_gaussian(A,7,sigma);
pyr{i} = A-B; %store result in cell array
if i==1
img2 = img3;
else
B = filter_gaussian(img2,7,sigma2); %anti-alias for downsampling
B = filter_gaussian(B,7,sigma2);
end
img2 = resample_bilinear(B,scl); %downsample for next level
end
%show_pyramid(pyr) %show pyramid if desired
%///////////////////////////////////////////////////////////////////////////////
function show_pyramid(pyr)
close all
[h,w] = size(pyr);
for i=1:
figure
imagesc(pyr{i});
colormap gray;
end
3\
function key = construct_key(px, py, img, sz)
pct = .75;
[h,w] = size(img);
[yoff,xoff] = meshgrid(-1:1,-1:1);
yoff = yoff(:)*pct;
xoff = xoff(:)*pct;
for i = 1:size(yoff,1)
ctrx = px + xoff(i)*sz*2; %method using interpolated values