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 --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 06/04/2004.
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 % INRA - TPV URPOI - BIA IMASTE 0023 % created the 06/04/2004. 0024 0025 % 14/08/2017 Updated by Juanpi Carbajal <ajuanpi+dev@gmail.com> 0026 0027 0028 % allocate memory 0029 dest = zeros(size(edge)); 0030 0031 % compute position 0032 for i=1:2 0033 T = trans(i,1:2).'; 0034 dest(:,i) = edge(:,1:2) * T; 0035 dest(:,i+2) = edge(:,3:4) * T; 0036 end 0037 0038 % add translation vector, if exist 0039 if size(trans, 2) > 2 0040 dest = bsxfun (@plus, dest, trans([1:2 1:2],3).'); 0041 end 0042