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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • 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;
73;
74  compile_opt idl2, strictarrsubs
75;
76tempsone = systime(1)
77;
78; Warning, wrong definition of (x2,y2) and (x3,y3) at the bottom of
79; page 54 of Wolberg's book, see figure 3.7 page 56 for the good
80; definition.
81;
82  IF keyword_set(double) THEN BEGIN
83    x0 = double(x0in)
84    x1 = double(x1in)
85    x2 = double(x2in)
86    x3 = double(x3in)
87    y0 = double(y0in)
88    y1 = double(y1in)
89    y2 = double(y2in)
90    y3 = double(y3in)
91    xin = double(xxin)
92    yin = double(yyin)
93  ENDIF ELSE BEGIN
94    x0 = float(x0in)
95    x1 = float(x1in)
96    x2 = float(x2in)
97    x3 = float(x3in)
98    y0 = float(y0in)
99    y1 = float(y1in)
100    y2 = float(y2in)
101    y3 = float(y3in)
102    xin = float(xxin)
103    yin = float(yyin)
104  ENDELSE
105;
106; get the matrix A
107;
108  a = square2quadrilateral(x0in, y0in, x1in, y1in, x2in, y2in, x3in, y3in)
109;
110; compute the adjoint matrix
111;
112  IF keyword_set(double) THEN adj = dblarr(9, n_elements(x0)) $
113  ELSE adj = fltarr(9, n_elements(x0))
114;
115  adj[0, *] = a[4, *]        -a[7, *]*a[5, *]
116  adj[1, *] = a[7, *]*a[2, *]-a[1, *]
117  adj[2, *] = a[1, *]*a[5, *]-a[4, *]*a[2, *]
118  adj[3, *] = a[6, *]*a[5, *]-a[3, *]
119  adj[4, *] = a[0, *]        -a[6, *]*a[2, *]
120  adj[5, *] = a[3, *]*a[2, *]-a[0, *]*a[5, *]
121  adj[6, *] = a[3, *]*a[7, *]-a[6, *]*a[4, *]
122  adj[7, *] = a[6, *]*a[1, *]-a[0, *]*a[7, *]
123  adj[8, *] = a[0, *]*a[4, *]-a[3, *]*a[1, *]
124
125  IF n_elements(xin) EQ 1 THEN BEGIN
126    xin = replicate(xin, n_elements(x0))
127    yin = replicate(yin, n_elements(x0))
128  ENDIF
129;
130; compute xprime, yprime and wprime
131;
132  IF n_elements(x0) EQ 1 THEN BEGIN
133    wpr = 1./(adj[6]*xin + adj[7]*yin + adj[8])
134  ENDIF ELSE BEGIN
135    wpr = 1./(adj[6, *]*xin + adj[7, *]*yin + adj[8, *])
136  ENDELSE
137  xpr = xin*wpr
138  ypr = yin*wpr
139;
140  IF keyword_set(double) THEN res = dblarr(2, n_elements(xin)) $
141  ELSE res = fltarr(2, n_elements(xin))
142;
143  IF n_elements(x0) EQ 1 THEN 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  ENDIF ELSE BEGIN
147    res[0, *] = xpr*adj[0, *] + ypr*adj[1, *] +wpr*adj[2, *]
148    res[1, *] = xpr*adj[3, *] + ypr*adj[4, *] +wpr*adj[5, *]
149  ENDELSE
150;
151  IF keyword_set(perf) THEN print, 'time quadrilateral2square', systime(1)-tempsone
152
153  RETURN, res
154END
Note: See TracBrowser for help on using the repository browser.