~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomImg_rectify.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 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 General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU 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  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  *
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomImg_rectify.c,v $
 27  * Date    :  $Date: 2008/12/04 15:28:02 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: geomImg_rectify.c,v 1.2 2008/12/04 15:28:02 paul Exp $
 30  *
 31  * Author  : Simon Crossley / NAT 
 32  *
 33  * Notes :
 34  *
 35  *********
 36 */
 37 
 38 #include "geomImg_rectify.h"
 39 
 40 #if HAVE_CONFIG_H
 41   #include <config.h>
 42 #endif
 43 
 44 #include <math.h>
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/geometry/geomDef.h>
 50 #include <tina/geometry/geomPro.h>
 51 #include <tina/image/imgDef.h>
 52 #include <tina/image/imgPro.h>
 53 
 54 /* 
 55     whole image rectification using sub pixel interpolation
 56 */
 57 
 58 static Imregion rectify_roi(Mat3 rec, Imregion *roi1)
 59 {
 60   Vec2 p1,p2,p3,p4;
 61   Vec3 w;
 62   Imregion roi2;
 63 
 64   vec2_x(p1) = (float)roi1->lx;
 65   vec2_y(p1) = (float)roi1->ly;
 66   w = proj3_of_vec2(p1);
 67   w = mat3_vprod(rec,w);
 68   p1 = proj2_of_vec3(w);
 69 
 70   vec2_x(p2) = (float)roi1->lx;
 71   vec2_y(p2) = (float)roi1->uy;
 72   w = proj3_of_vec2(p2);
 73   w = mat3_vprod(rec,w);
 74   p2 = proj2_of_vec3(w);
 75 
 76   vec2_x(p3) = (float)roi1->ux;
 77   vec2_y(p3) = (float)roi1->ly;
 78   w = proj3_of_vec2(p3);
 79   w = mat3_vprod(rec,w);
 80   p3 = proj2_of_vec3(w);
 81 
 82   vec2_x(p4) = (float)roi1->ux;
 83   vec2_y(p4) = (float)roi1->uy;
 84   w = proj3_of_vec2(p4);
 85   w = mat3_vprod(rec,w);
 86   p4 = proj2_of_vec3(w);
 87 
 88   if (vec2_x(p1)>vec2_x(p2)) roi2.lx = tina_rint(vec2_x(p1));
 89   else                       roi2.lx = tina_rint(vec2_x(p2));
 90 
 91   if (vec2_y(p1)>vec2_y(p3)) roi2.ly = tina_rint(vec2_y(p1));
 92   else                       roi2.ly = tina_rint(vec2_y(p3));
 93 
 94   if (vec2_x(p3)<vec2_x(p4)) roi2.ux = tina_rint(vec2_x(p3));
 95   else                       roi2.ux = tina_rint(vec2_x(p4));
 96 
 97   if (vec2_y(p2)<vec2_y(p4)) roi2.uy = tina_rint(vec2_y(p2));
 98   else                       roi2.uy = tina_rint(vec2_y(p4));
 99 
100   /* Added to prevent compiler warning PAB 04/12/2008 */
101   roi2.ts_id = Imregion_id;
102 
103   return(roi2);
104 }
105 
106 Imrect *imf_left_rectify(Imrect *im1, Imregion *roi, Parcam *pcam,
107                          double (*interp_func)(Imrect * image, float x,
108                                                float y, float *px, float *py))
109 {
110   Imrect *im2, *float_im;
111   Imregion *roi1, roi2;
112   float *row2;
113   int i, j;
114   float pdx, pdy;
115   Vec2 p;
116   Vec3 w;
117   Mat3 derec1;
118   Mat3 rec1;
119 
120   if (im1 == NULL)
121     return (NULL);
122 
123   if (im1->vtype != float_v)
124     float_im = im_cast(im1, float_v);
125   else 
126     float_im = im1;
127 
128   derec1 = pcam->derect1;
129   rec1 = pcam->rect1;
130   roi1 = float_im->region;
131   if (roi != NULL) roi1 = roi;
132 
133   roi2 = rectify_roi(rec1,roi1);
134 
135   im2 = im_alloc(float_im->height, float_im->width, &roi2, float_v);
136   row2 = fvector_alloc(roi2.lx, roi2.ux);
137 
138   for (i = roi2.ly; i < roi2.uy; ++i)
139     {
140       for (j = roi2.lx; j < roi2.ux; ++j)
141         {
142           vec2_y(p) = i+0.5;
143           vec2_x(p) = j+0.5;
144           w = proj3_of_vec2(p);
145           w = mat3_vprod(derec1,w);
146           p = proj2_of_vec3(w);
147           row2[j] = interp_func(float_im, vec2_x(p), vec2_y(p), &pdx, &pdy);
148           w = proj3_of_vec2(p);
149           w = mat3_vprod(rec1,w);
150           p = proj2_of_vec3(w);
151         }
152       im_put_rowf(row2, im2, i, roi2.lx, roi2.ux);
153     }
154 
155   if (im1->vtype != float_v)
156     im_free(float_im);
157 
158   fvector_free(row2, roi2.lx);
159   return (im2);
160 }
161 
162 Imrect *imf_right_rectify(Imrect *im1, Imregion* roi, Parcam *pcam,
163                           double (*interp_func)(Imrect * image, float x,
164                                                 float y, float *px, float *py))
165 {
166   Imrect *im2, *float_im;
167   Imregion *roi1, roi2;
168   float *row2;
169   int i, j;
170   float pdx, pdy;
171   Vec2 p;
172   Vec3 w;
173   Mat3 derec2;
174   Mat3 rec2;
175  
176   if (im1 == NULL)
177     return (NULL);
178  
179   if (im1->vtype != float_v)
180     float_im = im_cast(im1, float_v);
181   else 
182     float_im = im1;
183 
184   derec2 = pcam->derect2;
185   rec2 = pcam->rect2;
186   roi1 = float_im->region;
187   if (roi != NULL) roi1 = roi;
188 
189   roi2 = rectify_roi(rec2, roi1);
190  
191   im2 = im_alloc(float_im->height, float_im->width, &roi2, float_v);
192   row2 = fvector_alloc(roi2.lx, roi2.ux);
193 
194   for (i = roi2.ly; i < roi2.uy; ++i)
195     {
196       for (j = roi2.lx; j < roi2.ux; ++j)
197         {
198           vec2_y(p) = i+0.5;
199           vec2_x(p) = j+0.5;
200           w = proj3_of_vec2(p);
201           w = mat3_vprod(derec2,w);
202           p = proj2_of_vec3(w);
203           row2[j] = interp_func(float_im, vec2_x(p), vec2_y(p), &pdx, &pdy);
204         }
205       im_put_rowf(row2, im2, i, roi2.lx, roi2.ux);
206     }
207  
208   if (im1->vtype != float_v)
209     im_free(float_im);
210 
211   fvector_free(row2, roi2.lx);
212   return (im2);
213 }
214 
215 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.