1 /**********
2 *
3 * This file is part of the TINA Open Source Image Analysis Environment
4 * henceforth known as TINA
5 *
6 * TINA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation.
9 *
10 * TINA is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with TINA; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 **********
20 *
21 * Program : TINA
22 * File : $Source: /home/tina/cvs/tina-libs/tina/geometry/geomImg_rectify.c,v $
23 * Date : $Date: 2008/12/04 15:28:02 $
24 * Version : $Revision: 1.2 $
25 * CVS Id : $Id: geomImg_rectify.c,v 1.2 2008/12/04 15:28:02 paul Exp $
26 *
27 * Author : Simon Crossley / NAT
28 *
29 * Notes :
30 *
31 *********
32 */
33
34 #include "geomImg_rectify.h"
35
36 #if HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include <math.h>
41 #include <tina/sys/sysDef.h>
42 #include <tina/sys/sysPro.h>
43 #include <tina/math/mathDef.h>
44 #include <tina/math/mathPro.h>
45 #include <tina/geometry/geomDef.h>
46 #include <tina/geometry/geomPro.h>
47 #include <tina/image/imgDef.h>
48 #include <tina/image/imgPro.h>
49
50 /*
51 whole image rectification using sub pixel interpolation
52 */
53
54 static Imregion rectify_roi(Mat3 rec, Imregion *roi1)
55 {
56 Vec2 p1,p2,p3,p4;
57 Vec3 w;
58 Imregion roi2;
59
60 vec2_x(p1) = (float)roi1->lx;
61 vec2_y(p1) = (float)roi1->ly;
62 w = proj3_of_vec2(p1);
63 w = mat3_vprod(rec,w);
64 p1 = proj2_of_vec3(w);
65
66 vec2_x(p2) = (float)roi1->lx;
67 vec2_y(p2) = (float)roi1->uy;
68 w = proj3_of_vec2(p2);
69 w = mat3_vprod(rec,w);
70 p2 = proj2_of_vec3(w);
71
72 vec2_x(p3) = (float)roi1->ux;
73 vec2_y(p3) = (float)roi1->ly;
74 w = proj3_of_vec2(p3);
75 w = mat3_vprod(rec,w);
76 p3 = proj2_of_vec3(w);
77
78 vec2_x(p4) = (float)roi1->ux;
79 vec2_y(p4) = (float)roi1->uy;
80 w = proj3_of_vec2(p4);
81 w = mat3_vprod(rec,w);
82 p4 = proj2_of_vec3(w);
83
84 if (vec2_x(p1)>vec2_x(p2)) roi2.lx = tina_rint(vec2_x(p1));
85 else roi2.lx = tina_rint(vec2_x(p2));
86
87 if (vec2_y(p1)>vec2_y(p3)) roi2.ly = tina_rint(vec2_y(p1));
88 else roi2.ly = tina_rint(vec2_y(p3));
89
90 if (vec2_x(p3)<vec2_x(p4)) roi2.ux = tina_rint(vec2_x(p3));
91 else roi2.ux = tina_rint(vec2_x(p4));
92
93 if (vec2_y(p2)<vec2_y(p4)) roi2.uy = tina_rint(vec2_y(p2));
94 else roi2.uy = tina_rint(vec2_y(p4));
95
96 /* Added to prevent compiler warning PAB 04/12/2008 */
97 roi2.ts_id = Imregion_id;
98
99 return(roi2);
100 }
101
102 Imrect *imf_left_rectify(Imrect *im1, Imregion *roi, Parcam *pcam,
103 double (*interp_func)(Imrect * image, float x,
104 float y, float *px, float *py))
105 {
106 Imrect *im2, *float_im;
107 Imregion *roi1, roi2;
108 float *row2;
109 int i, j;
110 float pdx, pdy;
111 Vec2 p;
112 Vec3 w;
113 Mat3 derec1;
114 Mat3 rec1;
115
116 if (im1 == NULL)
117 return (NULL);
118
119 if (im1->vtype != float_v)
120 float_im = im_cast(im1, float_v);
121 else
122 float_im = im1;
123
124 derec1 = pcam->derect1;
125 rec1 = pcam->rect1;
126 roi1 = float_im->region;
127 if (roi != NULL) roi1 = roi;
128
129 roi2 = rectify_roi(rec1,roi1);
130
131 im2 = im_alloc(float_im->height, float_im->width, &roi2, float_v);
132 row2 = fvector_alloc(roi2.lx, roi2.ux);
133
134 for (i = roi2.ly; i < roi2.uy; ++i)
135 {
136 for (j = roi2.lx; j < roi2.ux; ++j)
137 {
138 vec2_y(p) = i+0.5;
139 vec2_x(p) = j+0.5;
140 w = proj3_of_vec2(p);
141 w = mat3_vprod(derec1,w);
142 p = proj2_of_vec3(w);
143 row2[j] = interp_func(float_im, vec2_x(p), vec2_y(p), &pdx, &pdy);
144 w = proj3_of_vec2(p);
145 w = mat3_vprod(rec1,w);
146 p = proj2_of_vec3(w);
147 }
148 im_put_rowf(row2, im2, i, roi2.lx, roi2.ux);
149 }
150
151 if (im1->vtype != float_v)
152 im_free(float_im);
153
154 fvector_free(row2, roi2.lx);
155 return (im2);
156 }
157
158 Imrect *imf_right_rectify(Imrect *im1, Imregion* roi, Parcam *pcam,
159 double (*interp_func)(Imrect * image, float x,
160 float y, float *px, float *py))
161 {
162 Imrect *im2, *float_im;
163 Imregion *roi1, roi2;
164 float *row2;
165 int i, j;
166 float pdx, pdy;
167 Vec2 p;
168 Vec3 w;
169 Mat3 derec2;
170 Mat3 rec2;
171
172 if (im1 == NULL)
173 return (NULL);
174
175 if (im1->vtype != float_v)
176 float_im = im_cast(im1, float_v);
177 else
178 float_im = im1;
179
180 derec2 = pcam->derect2;
181 rec2 = pcam->rect2;
182 roi1 = float_im->region;
183 if (roi != NULL) roi1 = roi;
184
185 roi2 = rectify_roi(rec2, roi1);
186
187 im2 = im_alloc(float_im->height, float_im->width, &roi2, float_v);
188 row2 = fvector_alloc(roi2.lx, roi2.ux);
189
190 for (i = roi2.ly; i < roi2.uy; ++i)
191 {
192 for (j = roi2.lx; j < roi2.ux; ++j)
193 {
194 vec2_y(p) = i+0.5;
195 vec2_x(p) = j+0.5;
196 w = proj3_of_vec2(p);
197 w = mat3_vprod(derec2,w);
198 p = proj2_of_vec3(w);
199 row2[j] = interp_func(float_im, vec2_x(p), vec2_y(p), &pdx, &pdy);
200 }
201 im_put_rowf(row2, im2, i, roi2.lx, roi2.ux);
202 }
203
204 if (im1->vtype != float_v)
205 im_free(float_im);
206
207 fvector_free(row2, roi2.lx);
208 return (im2);
209 }
210
211
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.