From: <dkg5@us...>  20090716 17:03:22

Revision: 1011 http://panotools.svn.sourceforge.net/panotools/?rev=1011&view=rev Author: dkg5 Date: 20090716 17:03:21 +0000 (Thu, 16 Jul 2009) Log Message:  fixed matlab code  works for all pixel coordinates Added Paths:  branches/libpano_gsoc2009_mosaic/matlab/mosaic_v19.m branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt3.m Added: branches/libpano_gsoc2009_mosaic/matlab/mosaic_v19.m ===================================================================  branches/libpano_gsoc2009_mosaic/matlab/mosaic_v19.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/mosaic_v19.m 20090716 17:03:21 UTC (rev 1011) @@ 0,0 +1,94 @@ +% Script for slanting and tilting points and images + +clear all, +clc + +ang = 10; +rotang = 10; +FOV = 50; +% Create five points forming square and its center. Transform and Recover. +% 1. Apply slant or tilt (transformed square) +% 2. Apply negative of slant or tilt (recovered square) +% 3. Plot input (blue stars), transformed square (green dots), +% and recovered (red circles) + +% Create corners of square as projective points in the form [x y 1] +% pts = [1 1 1;... +% 1 1 1;... +% 1 1 1;... +% 1 1 1;... +% 0 0 1] + +pts = [10 10 1;... + 10 10 1;... + 10 10 1;... + 10 10 1;... + 0 0 1;... + 1 1 1;... + 1 1 1;... + 1 1 1;... + 1 1 1;... + 100 100 1;... + 100 100 1;... + 100 100 1;... + 100 100 1] + +% pts = [ 8 8;... +% 8 8;... +% 6 6;... +% 6 6;... +% 0 0]; + +% Change points to column vectors +pts = pts' + +% find maximum ycoordinate +ymax = max(abs(pts(2,:))) +% FOV is full angle FOV so z0 is calculated using half of FOV +z0 = ymax/tand(FOV/2) + + +% Assign z coordinate of all points to be z0. +pts(3,:) = z0 + + +% Create tilted points by multiplying by tilt2() matrix (STRAIGHT TO TILT) +tiltedpts = tilt2(ang)*pts + +% Cartesian coordinates are found by dividing by zcoordinate, then +% multiplying by z0 +tiltedptscart = z0 .* [tiltedpts(1,:)./tiltedpts(3,:); tiltedpts(2,:)./tiltedpts(3,:)] + + + +% STEP 1: scale tilted points so that ray.... +adjpts = projectDepthTilt3(tiltedpts,rotang,z0) + + +% Make slant/tilt matrix +% really an UNtilting matrix (TILT TO STRAIGHT) +M = tilt3(rotang) + +% Create rotated projective points by multiplying slant matrix with +% projective points +% UNtilt adjpoints +outpts = M * adjpts + +% Convert outpts (in projective coordinates) to +% outcart (in cartesian coordinates) by dividing by zcoordinate +outcart = z0 .* [outpts(1,:)./outpts(3,:); outpts(2,:)./outpts(3,:)] +%outcart = [outpts(1,:); outpts(2,:)] + + + +% plot corners of square and slanted corners of square +figure(1), + +plot(pts(1,:), pts(2,:), '*', tiltedptscart(1,:), tiltedptscart(2,:), '.', ... + outcart(1,:), outcart(2,:), 'o'), +%plot(outcart(1,:), outcart(2,:), 'o'), + +axis image +legend('Original Points', 'Tilted/Slanted Points', 'Recovered Points') + + Added: branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt3.m ===================================================================  branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt3.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt3.m 20090716 17:03:21 UTC (rev 1011) @@ 0,0 +1,27 @@ +function out = projectDepthTilt3(M, phi, zDist) + +% should be passed N Cartesian coordinates as column vectors +% +% returns: + + +%%%%%%%%%%%%%% +% Gets Nx3 matrix of N (x0, y0, z0) pairs +% Returns Nx3 matrix of N (x1, y1, z1) points + +% This function calculates z1 based on y1 and phi + +x0 = M(1,:); +y0 = M(2,:); +z0 = M(3,:); + + +% scaling factor s = z0/(y0*tan(phi) + z0) +s = zDist./(y0 .* tand(phi) + zDist) + + +x1 = s .* x0 +y1 = s .* y0 +z1 = s .* z0 + +out = [x1; y1; z1]; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. 