Escolar Documentos
Profissional Documentos
Cultura Documentos
clear;
p = 2;
images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
addpath('../')
load face_adyoron_1_GS.mat
frame = face_adyoron_1_GS;
M = size(frame(:,:,1),1);
N = size(frame(:,:,1),2);
[m,n] = meshgrid(1:M,1:N);
%%%%%%%%% Find Translation Parameters %%%%%%%%%%%%%%%%%%%%%
K(1,:) = zeros(1,4);
for num= 2:p,
K(num,:) = affine(frame(:,:,num),frame(:,:,1));
end
deltaK = K(:,3:4);
%%%%%%%%%% Initialization %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Lu = 1;
Lv = 1;
Tx = 2;
Ty = 2;
wsx = 1./Tx;
wsy = 1./Ty;
F1 = fft2(frame(:,:,1));
F2 = fft2(frame(:,:,2));
F = zeros(2*Lu*M,2*Lv*N);
%%%%%%%%%%% Calculating values in matrix F
for n = 1:N,
disp(n);
for m = 1:M,
Gmn = [F1(m,n);F2(m,n)];
%%%%%%%%%%%%%%%%%%
for k=1:p,
for r = 1:4
PHImn(k,r) = exp(j*2*pi.*(deltaK(k,1)*(m./M*Tx)-(Lu/Tx)
+deltaK(k,2)*(n./N*Ty)-(Lv/Ty)))*...
exp(j*2*pi.*((deltaK(k,1)./Tx)*rem(r-1,2*Lu)+(deltaK(k,2)*floor((r1)./2*Lv))));
end
end
Fmn = pinv(PHImn)*Gmn;
F(m,n) = Fmn(4,1);
F(m+M,n) = Fmn(2,1);
F(m,n+N) = Fmn(3,1);
F(m+M,n+N) = Fmn(1,1);
end
end
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
% warp.m subroutine for Affine Parameter Calculation
% ------------------------------------------------% AUTHOR: Maher Khoury
%
DATE: March 1, 1999
% PURPOSE:
%
Motion Compensates frame2 using input u and v vectors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function warped = warp(im, k);
[x, y] = meshgrid(1:size(im,2), 1:size(im,1));
u = k(1).*x + k(2).*y + k(3);
v = -k(2).*x + k(1).*y + k(4);
x_warped = x + u;
y_warped = y + v;
warped = interp2(x, y, im, x_warped, y_warped, 'linear');
warped(isnan(warped)) = 0;
1
9
2
0
2
1
2
2
2
3
%
%
%
%
%
%
%
%
%
%
sy = size(small,1);
sx = size(small,2);
%% These values are one less than the index of the small mtx that falls on
%% the border pixel of the large matrix when computing the first
%% convolution response sample:
sy2 = floor((sy+ctr-1)/2);
sx2 = floor((sx+ctr-1)/2);
% pad with reflected copies
clarge = [
large(sy-sy2:-1:2,sx-sx2:-1:2), large(sy-sy2:-1:2,:), ...
large(sy-sy2:-1:2,lx-1:-1:lx-sx2); ...
large(:,sx-sx2:-1:2),
large,
large(:,lx-1:-1:lx-sx2); ...
large(ly-1:-1:ly-sy2,sx-sx2:-1:2), ...
large(ly-1:-1:ly-sy2,:), ...
large(ly-1:-1:ly-sy2,lx-1:-1:lx-sx2) ];
c = conv2(clarge,small,'valid');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parametric.m subroutine for Affine Parameter Calculation
% -------------------------------------------------------% AUTHOR: Maher Khoury
%
DATE: March 1, 1999
% PURPOSE:
%
Caluclates the affine parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function k = Parametric(Ix,Iy,It);
k(1:4) = 0;
[x, y] = meshgrid(1:size(Ix,2), 1:size(Ix,1));
%%% Initialize the values in the A matrix
A = zeros(4);
A(1,1) = sum(sum((x.*Ix+y.*Iy).^2));
A(1,2) = sum(sum((x.*Ix+y.*Iy).*(y.*Ix-x.*Iy)));
A(2,1) = A(1,2);
A(1,3) = sum(sum(Ix.*(x.*Ix+y.*Iy)));
A(3,1) = A(1,3);
A(1,4) = sum(sum(Iy.*(x.*Ix+y.*Iy)));
A(4,1) = A(1,4);
A(2,2) = sum(sum((y.*Ix-x.*Iy).^2));
A(2,3) = sum(sum(Ix.*(y.*Ix-x.*Iy)));
A(3,2) = A(2,3);
A(2,4) = sum(sum(Iy.*(y.*Ix-x.*Iy)));
A(4,2) = A(2,4);
A(3,3) = sum(sum(Ix.^2));
A(3,4) = sum(sum(Ix.*Iy));
A(4,3) = A(3,4);
A(4,4) = sum(sum(Iy.^2));
%%% Initialize the values in the B matrix
B = zeros(4,1);
B(1,1) = sum(sum(It.*(x.*Ix+y.*Iy)));
B(2,1) = sum(sum(It.*(y.*Ix-x.*Iy)));
B(3,1) = sum(sum(It.*Ix));
B(4,1) = sum(sum(It.*Iy));
B = -B;
%%% Calculate the k parameters
C = inv(A)*B;
k = C';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% grad.m subroutine for Affine Parameter Calculation
% -------------------------------------------------% AUTHOR: Maher Khoury
%
DATE: March 1, 1999
% PURPOSE:
%
Caluclates the image gradients in 3 dimensions given
%
two input frames
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Ix, Iy, It] = grad(im1, im2);
%%%% Defime the size of the gradients
sizey = size(im1,1);
sizex = size(im1,2);
%%%% Get neighbouring pixels %%%%
im1_right = im1(1:sizey-1, 2:sizex);
im1_down = im1(2:sizey,1:sizex-1);
im1_down_right = im1(2:sizey,2:sizex);
im2_right = im2(1:sizey-1, 2:sizex);
im2_down = im2(2:sizey,1:sizex-1);
im2_down_right = im2(2:sizey,2:sizex);
%%%% Calculate Ix %%%%
Ix = zeros(sizey,sizex);
Ix(1:sizey-1,1:1:sizex-1) = 0.25.*(im1_right + im2_right + im1_down_right +
im2_down_right - ...
(im1(1:sizey-1, 1:sizex-1) + im2(1:sizey-1,1:sizex-1) + im1_down +
im2_down));
Ix(sizey,:) = 0;
Ix(:,sizex) = 0;
%%%% Calculate Iy %%%%
Iy = zeros(sizey,sizex);