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.
|