TRANSFORMEDGE Transform an edge with an affine transform. EDGE2 = transformEdge(EDGE1, TRANS); where EDGE1 has the form [x1 y1 x2 y1], and TRANS is a transformation matrix, return the edge transformed with affine transform TRANS. Format of TRANS can be one of : [a b] , [a b c] , or [a b c] [d e] [d e f] [d e f] [0 0 1] EDGE2 = transformEdge(EDGES, TRANS); Also wotk when EDGES is a [N*4] array of double. In this case, EDGE2 has the same size as EDGE. See also edges2d, transforms2d, transformPoint, translation, rotation
0001 function dest = transformEdge(edge, trans) 0002 %TRANSFORMEDGE Transform an edge with an affine transform. 0003 % 0004 % EDGE2 = transformEdge(EDGE1, TRANS); 0005 % where EDGE1 has the form [x1 y1 x2 y1], and TRANS is a transformation 0006 % matrix, return the edge transformed with affine transform TRANS. 0007 % 0008 % Format of TRANS can be one of : 0009 % [a b] , [a b c] , or [a b c] 0010 % [d e] [d e f] [d e f] 0011 % [0 0 1] 0012 % 0013 % EDGE2 = transformEdge(EDGES, TRANS); 0014 % Also wotk when EDGES is a [N*4] array of double. In this case, EDGE2 0015 % has the same size as EDGE. 0016 % 0017 % See also 0018 % edges2d, transforms2d, transformPoint, translation, rotation 0019 0020 % ------ 0021 % Author: David Legland 0022 % E-mail: david.legland@inrae.fr 0023 % Created: 2004-04-06 0024 % Copyright 2004-2024 INRA - TPV URPOI - BIA IMASTE 0025 0026 % allocate memory 0027 dest = zeros(size(edge)); 0028 0029 % compute position 0030 for i=1:2 0031 T = trans(i,1:2).'; 0032 dest(:,i) = edge(:,1:2) * T; 0033 dest(:,i+2) = edge(:,3:4) * T; 0034 end 0035 0036 % add translation vector, if exist 0037 if size(trans, 2) > 2 0038 dest = bsxfun (@plus, dest, trans([1:2 1:2],3).'); 0039 end 0040