## [panotools-cvs] SF.net SVN: panotools:[1011] branches/libpano_gsoc2009_mosaic/matlab

 [panotools-cvs] SF.net SVN: panotools:[1011] branches/libpano_gsoc2009_mosaic/matlab From: - 2009-07-16 17:03:22 ```Revision: 1011 http://panotools.svn.sourceforge.net/panotools/?rev=1011&view=rev Author: dkg5 Date: 2009-07-16 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 2009-07-16 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 y-coordinate +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 z-coordinate, 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 UN-tilting matrix (TILT TO STRAIGHT) +M = tilt3(rotang) + +% Create rotated projective points by multiplying slant matrix with +% projective points +% UN-tilt adjpoints +outpts = M * adjpts + +% Convert outpts (in projective coordinates) to +% outcart (in cartesian coordinates) by dividing by z-coordinate +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 2009-07-16 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. ```

 [panotools-cvs] SF.net SVN: panotools:[995] branches/libpano_gsoc2009_mosaic/matlab From: - 2009-06-17 21:20:59 ```Revision: 995 http://panotools.svn.sourceforge.net/panotools/?rev=995&view=rev Author: dkg5 Date: 2009-06-17 21:20:39 +0000 (Wed, 17 Jun 2009) Log Message: ----------- added GPL to matlab Modified Paths: -------------- branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m branches/libpano_gsoc2009_mosaic/matlab/mosaic_v6.m branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m branches/libpano_gsoc2009_mosaic/matlab/rot.m branches/libpano_gsoc2009_mosaic/matlab/slant.m branches/libpano_gsoc2009_mosaic/matlab/tilt.m branches/libpano_gsoc2009_mosaic/matlab/trans.m Modified: branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,17 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + function [proj] = cart2proj(cart) % USAGE: proj = cart2proj(cart) % Converts cartesian coordinates to projective by appending 1 to end Modified: branches/libpano_gsoc2009_mosaic/matlab/mosaic_v6.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/mosaic_v6.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/mosaic_v6.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,18 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + clear all; %close all; Modified: branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,17 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + function [cart] = proj2cart(proj) % USAGE: cart = proj2cart(proj) % Converts projective coordinates to cartesian by dividing by z Modified: branches/libpano_gsoc2009_mosaic/matlab/rot.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/rot.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/rot.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,17 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + function [out, rotmat] = rot(vproj, ang, ax) % USAGE: out = rot(vproj, ang, ax) % Rotates vproj about axis, ax, by angle, ang. Modified: branches/libpano_gsoc2009_mosaic/matlab/slant.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/slant.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/slant.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,18 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + function M = slant(L, ang) % USAGE: M = slant(L, ang) % -accepts L, a 2 element vector describing the location of the LookAtPoint Modified: branches/libpano_gsoc2009_mosaic/matlab/tilt.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/tilt.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/tilt.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,17 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + function M = tilt(L, ang) % USAGE: M = tilt(L, ang) % -accepts L, a 2 element vector describing the location of the LookAtPoint Modified: branches/libpano_gsoc2009_mosaic/matlab/trans.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/trans.m 2009-06-16 22:41:43 UTC (rev 994) +++ branches/libpano_gsoc2009_mosaic/matlab/trans.m 2009-06-17 21:20:39 UTC (rev 995) @@ -1,3 +1,17 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + function [vout, T] = trans(vproj, vtrans) % USAGE: out = trans(vproj, vtrans) % Translates vproj by vector vtrans This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [panotools-cvs] SF.net SVN: panotools:[998] branches/libpano_gsoc2009_mosaic/matlab From: - 2009-06-23 07:30:48 ```Revision: 998 http://panotools.svn.sourceforge.net/panotools/?rev=998&view=rev Author: dkg5 Date: 2009-06-23 07:29:56 +0000 (Tue, 23 Jun 2009) Log Message: ----------- week 4 matlab model Added Paths: ----------- branches/libpano_gsoc2009_mosaic/matlab/mosaic_v11.m branches/libpano_gsoc2009_mosaic/matlab/slant2.m branches/libpano_gsoc2009_mosaic/matlab/slant3.m Added: branches/libpano_gsoc2009_mosaic/matlab/mosaic_v11.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/mosaic_v11.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/mosaic_v11.m 2009-06-23 07:29:56 UTC (rev 998) @@ -0,0 +1,103 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +% Script for slanting and tilting points and images + +clear all, +clc + +ang = -30; +%% 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 circles), +% and recovered (red squares) + +% 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]; + +% Change projective points to column vectors +pts = pts' + + +% Make slant matrix +M = slant2(ang); +Mback = slant3(ang) +% or tilt matrix +%M = M * tilt3(11.3); + +% Create rotated projective points by multiplying slant matrix to +% projective points +outpts = M * pts + +% Recover input points by multiplying outpts by inverting slant matrix +% (matrix with negative of angle used for forward slant matrix) +recpts = Mback * outpts; + +% Convert outpts (in projective coordinates) to +% outcart (in cartesian coordinates) by dividing by z-coordinate +outcart = [outpts(1,:)./outpts(3,:); outpts(2,:)./outpts(3,:)] +reccart = [recpts(1,:)./recpts(3,:); recpts(2,:)./recpts(3,:)] + +% plot corners of square and slanted corners of square +figure(1), +plot(pts(1,:), pts(2,:), '*', outcart(1,:), outcart(2,:), 'o', reccart(1,:), reccart(2,:), 's'), +axis image +legend('Original Points', 'Tilted/Slanted Points', 'Recovered Points') + + +%% Slant or Tilt synthetic image or image loaded from disk +% Create synthetic square image +im = zeros(200,200); +pixsel = 50:150; +im(pixsel,50:51) = 255; +im(50:51,pixsel) = 255; +im(pixsel,150:151) = 255; +im(150:151,pixsel) = 255; +% End of synthetic square image + +% Or load camera man image +%im = imread('cameraman.tif'); +im = imread('grid_transformed2.tif'); +% transformed grid image, created in Hugin, has an alpha channel. +% just keep the R,G,and B channels. +im = im(:,:,1:3); + +udata = [-1 1]; vdata = [-1 1];% input coordinate system +Corig = pts(1:2,1:4)'; % Grab input square points +Cnew = outcart(:,1:4)'; % Grab corresponding slanted quadrilateral + +% Uses MATLAB's transform generator to create transform stucture +tform = maketform('projective',Corig,Cnew); +[B,xdata,ydata] = imtransform(im, tform, 'bicubic', ... + 'udata', udata,... + 'vdata', vdata,... + 'size', size(im),... + 'fill', 128); + +imwrite(B, 'grid_recovered6.png', 'PNG') + +% Display original image and slanted/tilted image +figure(2), +imagesc(udata,vdata,im), axis on, axis image, colormap(gray), +title('input') + +figure(3), +imagesc(xdata,ydata,B), axis on, axis image, colormap(gray), +title('ouput after slant or tilt') \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/slant2.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/slant2.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/slant2.m 2009-06-23 07:29:56 UTC (rev 998) @@ -0,0 +1,24 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +function M = slant2(ang) +% USAGE: M = slant2(ang) +% Makes 3x3 rotation matrix, M. Given a 3-element column vector, +% v=[x,y,z]' to describe a point in 3D, (M*v) rotates v about an axis +% stretching upwards from [0 0 Z0]' in the +y direction rotating by +% angle ang in DEGREES. + +M = [ cosd(ang) 0 0;... + 0 1 0;... + -sind(ang) 0 1]; \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/slant3.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/slant3.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/slant3.m 2009-06-23 07:29:56 UTC (rev 998) @@ -0,0 +1,24 @@ +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +function M = slant3(ang) +% USAGE: M = slant2(ang) +% Makes 3x3 rotation matrix, M. Given a 3-element column vector, +% v=[x,y,z]' to describe a point in 3D, (M*v) rotates v about an axis +% stretching upwards from [0 0 Z0]' in the +y direction rotating by +% angle ang in DEGREES. + +M = [ 1/cosd(ang) 0 0;... + 0 1 0;... + sind(ang)/cosd(ang) 0 1]; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [panotools-cvs] SF.net SVN: panotools:[1011] branches/libpano_gsoc2009_mosaic/matlab From: - 2009-07-16 17:03:22 ```Revision: 1011 http://panotools.svn.sourceforge.net/panotools/?rev=1011&view=rev Author: dkg5 Date: 2009-07-16 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 2009-07-16 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 y-coordinate +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 z-coordinate, 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 UN-tilting matrix (TILT TO STRAIGHT) +M = tilt3(rotang) + +% Create rotated projective points by multiplying slant matrix with +% projective points +% UN-tilt adjpoints +outpts = M * adjpts + +% Convert outpts (in projective coordinates) to +% outcart (in cartesian coordinates) by dividing by z-coordinate +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 2009-07-16 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. ```
 [panotools-cvs] SF.net SVN: panotools:[1005] branches/libpano_gsoc2009_mosaic/matlab From: - 2009-07-10 07:44:40 ```Revision: 1005 http://panotools.svn.sourceforge.net/panotools/?rev=1005&view=rev Author: dkg5 Date: 2009-07-10 07:44:34 +0000 (Fri, 10 Jul 2009) Log Message: ----------- new try at slant/tilt functions Added Paths: ----------- branches/libpano_gsoc2009_mosaic/matlab/mosaic_v17.m branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt2.m Added: branches/libpano_gsoc2009_mosaic/matlab/mosaic_v17.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/mosaic_v17.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/mosaic_v17.m 2009-07-10 07:44:34 UTC (rev 1005) @@ -0,0 +1,68 @@ +% Script for slanting and tilting points and images + +clear all, +clc + +ang = -47; +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 circles), +% and recovered (red squares) + +% 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 = [-1.8 -1.8 1;... +% -1.8 1.8 1;... +% 1.8 -1.8 1;... +% 1.8 1.8 1;... +% 0 0 1] + +pts = [ 8 8;... + -8 8;... + 3 -3;... + -3 -3;... + 0 0]; + +% Change points to column vectors +pts = pts' + + +ymax = abs(max(pts(2,:))) +% FOV is full angle FOV so z0 is calculated using half of FOV +z0 = ymax/tand(FOV/2) + + +adjpts = projectDepthTilt2(pts,ang,z0) + + +% Make slant/tilt matrix +M = tilt2(ang) + +% Create rotated projective points by multiplying slant matrix with +% projective points +outpts = M * adjpts + +% Convert outpts (in projective coordinates) to +% outcart (in cartesian coordinates) by dividing by z-coordinate +outcart = [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,:), '*', outcart(1,:), outcart(2,:), 'o'), +%plot(outcart(1,:), outcart(2,:), 'o'), + +axis image +legend('Original Points', 'Tilted/Slanted Points') + + Added: branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt2.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt2.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/projectDepthTilt2.m 2009-07-10 07:44:34 UTC (rev 1005) @@ -0,0 +1,46 @@ +function out = projectDepthTilt2(M, phi, z0) + +% should be passed N Cartesian coordinates as column vectors +% if M is 2xN assume z0 = 1, then convert to get adjusted projective +% coordinate +% otherwise M should be 3xN and z0 is given for each coordinate + +% returns: + +%if size(M,1) == 2 +% M = [M; ones(1,size(M,2))]; +%end + + +%%%%%%%%%%%%%% +% Gets Nx2 matrix of N (x1, y1) pairs +% Returns Nx3 matrix of N (x1, y1, z1) points + +% This function calculates z1 based on y1 and phi + +x1 = M(1,:); +y1 = M(2,:); + +%z0 = 1 +%z1 = zeros(size(y1)); + + +z1 = z0 - y1*tand(phi); + + +% for i = 1:length(y1) +% if y1(i) >= 0 +% z1(i) = z0 - y1(i)*tand(phi); +% end +% if y1(i) < 0 +% z1(i) = y1(i)*tand(phi) - z0; +% end +% end + + + +% z1 = (z0 - y1*tand(phi)) .* (y1>=0) +... +% (y1*tand(phi) - z0) .* (y1<0); + + +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. ```