1 | function varargout = affine(A,T,varargin) |
---|
2 | % AFFINE Apply affine transformation to points |
---|
3 | % Y = AFFINE(A,T,X) applies the affine transformatio (A,T) to points |
---|
4 | % X. X contains one point per column. |
---|
5 | % |
---|
6 | % [Y1,Y2,...] = AFFINE(A,T,X1,X2,...) applies the affine |
---|
7 | % transformations to points (X1,X2,...). Arrays X1,X2,... contain one |
---|
8 | % of the coordinates of the points each. |
---|
9 | |
---|
10 | % AUTORIGHTS |
---|
11 | % Copyright (C) 2006 Andrea Vedaldi |
---|
12 | % |
---|
13 | % This file is part of VLUtil. |
---|
14 | % |
---|
15 | % VLUtil is free software; you can redistribute it and/or modify |
---|
16 | % it under the terms of the GNU General Public License as published by |
---|
17 | % the Free Software Foundation; either version 2, or (at your option) |
---|
18 | % any later version. |
---|
19 | % |
---|
20 | % This program is distributed in the hope that it will be useful, |
---|
21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
23 | % GNU General Public License for more details. |
---|
24 | % |
---|
25 | % You should have received a copy of the GNU General Public License |
---|
26 | % along with this program; if not, write to the Free Software Foundation, |
---|
27 | % Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
28 | |
---|
29 | if numel(varargin)==1 |
---|
30 | |
---|
31 | X = varargin{1} ; |
---|
32 | |
---|
33 | [n,k] = size(X); |
---|
34 | if n == 2 |
---|
35 | Y(1,:) = A(1,1)*X(1,:) + A(1,2)*X(2,:) + T(1) ; |
---|
36 | Y(2,:) = A(2,1)*X(1,:) + A(2,2)*X(2,:) + T(2) ; |
---|
37 | elseif n == 3 |
---|
38 | Y(1,:) = A(1,1)*X(1,:) + A(1,2)*X(2,:) + A(1,3) * X(3,:) + T(1) ; |
---|
39 | Y(2,:) = A(2,1)*X(1,:) + A(2,2)*X(2,:) + A(2,3) * X(3,:) + T(2) ; |
---|
40 | Y(3,:) = A(3,1)*X(1,:) + A(3,2)*X(2,:) + A(3,3) * X(3,:) + T(3) ; |
---|
41 | else |
---|
42 | Y = A*X + repmat(T,1,k) ; |
---|
43 | end |
---|
44 | |
---|
45 | varargout{1} = Y ; |
---|
46 | |
---|
47 | else |
---|
48 | |
---|
49 | n = numel(varargin) ; |
---|
50 | |
---|
51 | if n == 2 |
---|
52 | varargout{1} = A(1,1)*varargin{1} + A(1,2)*varargin{2} + T(1) ; |
---|
53 | varargout{2} = A(2,1)*varargin{1} + A(2,2)*varargin{2} + T(2) ; |
---|
54 | elseif n == 3 |
---|
55 | varargout{1} = A(1,1)*varargin{1} + A(1,2)*varargin{2} + A(1,3)*varargin{3} + T(1) ; |
---|
56 | varargout{2} = A(2,1)*varargin{1} + A(2,2)*varargin{2} + A(2,3)*varargin{3} + T(2) ; |
---|
57 | varargout{3} = A(3,1)*varargin{1} + A(3,2)*varargin{2} + A(3,3)*varargin{3} + T(3) ; |
---|
58 | else |
---|
59 | for i=1:n |
---|
60 | varargout{i} = T(i) * ones(size(varargin{1})) ; |
---|
61 | for j=1:n |
---|
62 | varargout{i} = varargout{i} + A(i,j)*varargin{j} ; |
---|
63 | end |
---|
64 | end |
---|
65 | end |
---|
66 | end |
---|