source: trunk/SRC/Interpolation/quadrilateral2square.pro @ 101

Last change on this file since 101 was 101, checked in by pinsard, 18 years ago

start to modify headers of Interpolation *.pro files for better idldoc output

  • Property svn:executable set to *
File size: 5.1 KB
Line 
1;+
2;
3; @file_comments warm (or map) an arbitrary quadrilateral onto a unit square
4; according to the 4-point correspondences:
5;       (x0,y0) -> (0,0)
6;       (x1,y1) -> (1,0)
7;       (x2,y2) -> (1,1)
8;       (x3,y3) -> (0,1)
9; This is the inverse function of square2quadrilateral.pro
10; The mapping is done using perspective transformation which preserve
11; lines in all orientations and permit quadrilateral to quadrilateral
12; mappings. see ref. bellow.
13;
14; @categories image, grid manipulation
15;
16; @examples
17;
18;     res = square2quadrilateral(x0,y0,x1,y1,x2,y2,x3,y3,xin,yin)
19;
20;     @param x0in {in}{required}  the coordinates of the quadrilateral
21;     @param y0in {in}{required}  the coordinates of the quadrilateral
22;     @param x1in {in}{required}  the coordinates of the quadrilateral
23;     @param y1in {in}{required}  the coordinates of the quadrilateral
24;     @param x2in {in}{required}  the coordinates of the quadrilateral
25;     @param y2in {in}{required}  the coordinates of the quadrilateral
26;     @param x3in {in}{required}  the coordinates of the quadrilateral
27;     @param y3in  {in}{required}  the coordinates of the quadrilateral
28;     (see above for correspondance with the unit square). Can be
29;     scalar or array. (x0,y0), (x1,y1), (x2,y2) and (x3,y3) are
30;     given in the anticlockwise order.
31;
32;     @param xxin {in}{required} the coordinates of the point(s) for which we want to do the
33;     mapping. Can be scalar or array.
34;     @param yyin {in}{required} the coordinates of the point(s) for which we want to do the
35;     mapping. Can be scalar or array.
36;
37; @returns
38;
39;     (2,n) array: the new coodinates (xout, yout) of the (xin,yin)
40;     point(s) after mapping.
41;     If xin is a scalar, then n is equal to the number of elements of
42;     x0. If xin is an array , then n is equal to the number of
43;     elements of xin.
44;
45; @restrictions I think degenerated quadrilateral (e.g. flat of
46; twisted) is not work. This has to be tested.
47;
48; @examples
49;
50; IDL> splot,[0,5],[0,3],/nodata,xstyle=1,ystyle=1
51; IDL> tracegrille, findgen(11)*.1, findgen(11)*.1,color=indgen(12)*20
52; IDL> xin = (findgen(11)*.1)#replicate(1, 11)
53; IDL> yin = replicate(1, 11)#(findgen(11)*.1)
54; IDL> out = square2quadrilateral(2,1,3,0,5,1,2,3, xin, yin)
55; IDL> tracegrille, reform(out[0,*],11,11), reform(out[1,*],11,11),color=indgen(12)*20
56;
57; IDL> inorg=quadrilateral2square(2,1,3,0,5,1,2,3,out[0,*],out[1,*])
58; IDL> tracegrille, reform(inorg[0,*],11,11), reform(inorg[1,*],11,11),color=indgen(12)*20
59;
60; @history
61;      Sebastien Masson (smasson\@lodyc.jussieu.fr)
62;      August 2003
63;      Based on "Digital Image Warping" by G. Wolberg
64;      IEEE Computer Society Press, Los Alamitos, California
65;      Chapter 3, see p 52-56
66;     
67;-
68;------------------------------------------------------------
69;------------------------------------------------------------
70;------------------------------------------------------------
71FUNCTION quadrilateral2square, x0in, y0in, x1in, y1in, x2in, y2in, x3in, y3in, xxin, yyin, PERF = perf
72;
73tempsone = systime(1)
74;
75; Warning, wrong definition of (x2,y2) and (x3,y3) at the bottom of
76; page 54 of Wolberg's book, see figure 3.7 page 56 for the good
77; definition.
78;
79  IF keyword_set(double) THEN BEGIN
80    x0 = double(x0in)
81    x1 = double(x1in)
82    x2 = double(x2in)
83    x3 = double(x3in)
84    y0 = double(y0in)
85    y1 = double(y1in)
86    y2 = double(y2in)
87    y3 = double(y3in)
88    xin = double(xxin)
89    yin = double(yyin)
90  ENDIF ELSE BEGIN
91    x0 = float(x0in)
92    x1 = float(x1in)
93    x2 = float(x2in)
94    x3 = float(x3in)
95    y0 = float(y0in)
96    y1 = float(y1in)
97    y2 = float(y2in)
98    y3 = float(y3in)
99    xin = float(xxin)
100    yin = float(yyin)
101  ENDELSE
102;
103; get the matrix A
104;
105  a = square2quadrilateral(x0in, y0in, x1in, y1in, x2in, y2in, x3in, y3in)
106;
107; compute the adjoint matrix
108;
109  IF keyword_set(double) THEN adj = dblarr(9, n_elements(x0)) $
110  ELSE adj = fltarr(9, n_elements(x0))
111;
112  adj[0, *] = a[4, *]        -a[7, *]*a[5, *]
113  adj[1, *] = a[7, *]*a[2, *]-a[1, *]
114  adj[2, *] = a[1, *]*a[5, *]-a[4, *]*a[2, *]
115  adj[3, *] = a[6, *]*a[5, *]-a[3, *]
116  adj[4, *] = a[0, *]        -a[6, *]*a[2, *]
117  adj[5, *] = a[3, *]*a[2, *]-a[0, *]*a[5, *]
118  adj[6, *] = a[3, *]*a[7, *]-a[6, *]*a[4, *]
119  adj[7, *] = a[6, *]*a[1, *]-a[0, *]*a[7, *]
120  adj[8, *] = a[0, *]*a[4, *]-a[3, *]*a[1, *]
121
122  IF n_elements(xin) EQ 1 THEN BEGIN
123    xin = replicate(xin, n_elements(x0))
124    yin = replicate(yin, n_elements(x0))
125  ENDIF
126;
127; compute xprime, yprime and wprime
128;
129  IF n_elements(x0) EQ 1 THEN BEGIN
130    wpr = 1./(adj[6]*xin + adj[7]*yin + adj[8])
131  ENDIF ELSE BEGIN
132    wpr = 1./(adj[6, *]*xin + adj[7, *]*yin + adj[8, *])
133  ENDELSE
134  xpr = xin*wpr
135  ypr = yin*wpr
136;
137  IF keyword_set(double) THEN res = dblarr(2, n_elements(xin)) $
138  ELSE res = fltarr(2, n_elements(xin))
139;
140  IF n_elements(x0) EQ 1 THEN BEGIN
141    res[0, *] = xpr*adj[0] + ypr*adj[1] +wpr*adj[2]
142    res[1, *] = xpr*adj[3] + ypr*adj[4] +wpr*adj[5]
143  ENDIF ELSE BEGIN
144    res[0, *] = xpr*adj[0, *] + ypr*adj[1, *] +wpr*adj[2, *]
145    res[1, *] = xpr*adj[3, *] + ypr*adj[4, *] +wpr*adj[5, *]
146  ENDELSE
147;
148  IF keyword_set(perf) THEN print, 'time quadrilateral2square', systime(1)-tempsone
149
150  RETURN, res
151END
Note: See TracBrowser for help on using the repository browser.