dh2 (directed homography)

clear
close all
% test1  filename='mod_3.jpg';
filename = 'script5c.jpg';
rgb = imread(filename);
imshow(rgb);
thetad = atan(23/3)*180/pi

vi = [1 0 0];
theta = thetad*pi/180;
vk = [0 sin(theta) cos(theta)]; % [1 0 0] at end
vj = cross(vk,vi);
R = [vi; vj; vk];
f = 879.2;

%pt = [320 320];
pt = [320 320+ 300*sin(theta)];

alphad = 5;
alpha = alphad*pi/180;
vi = [cos(alpha) sin(alpha) 0];
vk = [0 0 1];
vj = cross(vk,vi);
R2 = [vi; vj; vk];


KK = [ f 0 320; 0 f 320; 0 0 1];
T1 = R2*R/KK;

newcp = h2e(T1*e2h(pt'));

M = [300 0 0; 0 300 0; 0 0 1]*[eye(2,2) -newcp ;  0 0 1];
T = M*T1;

tf = projective2d(T');
NW = 400;
imageSize = [800 800];
xWorldLimits = [-NW NW];
yWorldLimits = [-NW NW];

RA = imref2d(imageSize,xWorldLimits,yWorldLimits);

[out, RB] = imwarp(rgb,tf,'OutputView',RA);
imshow(out);
thetad =

   82.5686

Warning: Image is too big to fit on screen;
displaying at 67% 
N = 800;
set(gcf,'Position',[100 100 N N]);
set(gca,'Position',[0 0 1 1]);

f = getframe(gcf);
filename = 'dh2a.jpg';
imwrite(f.cdata,filename);