1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_warp.c,v $
37 * Date : $Date: 2003/09/30 16:53:49 $
38 * Version : $Revision: 1.6 $
39 * CVS Id : $Id: imgPrc_warp.c,v 1.6 2003/09/30 16:53:49 ipoole Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief General image warping with a user defined tranformation.
47 *
48 * Uses quadratic sub-pixel interpolation rather than Sinc, for reasons of speed.
49 *
50 */
51
52 #include "imgPrc_warp.h"
53
54 #if HAVE_CONFIG_H
55 #include <config.h>
56 #endif
57
58 #include <math.h>
59 #include <tina/sys/sysDef.h>
60 #include <tina/sys/sysPro.h>
61 #include <tina/math/mathDef.h>
62 #include <tina/math/mathPro.h>
63 #include <tina/image/img_GenDef.h>
64 #include <tina/image/img_GenPro.h>
65
66
67
68 void imf_warp(Imrect * im1, Imrect * im2, Vec2(*f) ( /* ??? */ ), void *data)
69 {
70 double x, y;
71 Imregion *roi;
72
73 roi = im2->region;
74
75 for (x = roi->lx + 0.5; x < roi->ux; x++)
76 for (y = roi->ly + 0.5; y < roi->uy; y++)
77 {
78 double pixval;
79 Vec2 v1 = {Vec2_id};
80 Vec2 v2 = {Vec2_id};
81
82 v2 = vec2(x, y);
83 v1 = (*f) (v2, data);
84 pixval = im_sub_pixf(im1, vec2_y(v1), vec2_x(v1));
85 im_put_pixf(pixval, im2, (int) y, (int) x);
86 }
87 }
88
89 Imrect *im_warp(Imrect * im1, Vec2(*f) ( /* ??? */ ), void *data)
90 {
91 Imrect *im2;
92 double x, y;
93 Imregion *roi;
94
95 if (im1 == NULL)
96 return (NULL);
97
98 roi = im1->region;
99 im2 = im_copy(im1);
100
101 for (x = roi->lx + 0.5; x < roi->ux; x++)
102 for (y = roi->ly + 0.5; y < roi->uy; y++)
103 {
104 double pixval;
105 Vec2 v1 = {Vec2_id};
106 Vec2 v2 = {Vec2_id};
107
108 v2 = vec2(x, y);
109 v1 = (*f) (v2, data);
110 pixval = im_sub_pixf(im1, vec2_y(v1), vec2_x(v1));
111 im_put_pixf(pixval, im2, (int) y, (int) x);
112 }
113 return (im2);
114 }
115
116 Imregion *roi_rectify(Imregion * roi, Mat3 rect)
117 {
118 Vec2 v = {Vec2_id};
119 Vec2 vmin = {Vec2_id};
120 Vec2 vmax = {Vec2_id};
121 int lx, ly, ux, uy;
122
123 if (roi == NULL)
124 return (NULL);
125
126 v = vec2_rectify(rect, vec2((double) roi->lx, (double) roi->ly));
127 vmin = vmax = v;
128 v = vec2_rectify(rect, vec2((double) roi->ux + 1, (double) roi->ly));
129 vec2_extend_hull(&vmin, &vmax, v);
130 v = vec2_rectify(rect, vec2((double) roi->lx, (double) roi->uy + 1));
131 vec2_extend_hull(&vmin, &vmax, v);
132 v = vec2_rectify(rect, vec2((double) roi->ux + 1, (double) roi->uy + 1));
133 vec2_extend_hull(&vmin, &vmax, v);
134
135 lx = (int) floor(vec2_x(vmin));
136 ux = (int) (ceil(vec2_x(vmax)) - 0.5);
137 ly = (int) floor(vec2_y(vmin));
138 uy = (int) (ceil(vec2_y(vmax)) - 0.5);
139
140 return (roi_alloc(lx, ly, ux, uy));
141 }
142
143 Imrect *im_rectify(Imrect * im1, Mat3 rect)
144 {
145 Mat3 irect = {Mat3_id};
146 Imrect *im2;
147 Imregion *roi;
148 int x, y, lx, ly, ux, uy;
149
150 if (im1 == NULL)
151 return (NULL);
152
153 roi = roi_rectify(im1->region, rect);
154
155 im2 = im_alloc(im1->height, im1->width, roi, im1->vtype);
156 lx = roi->lx;
157 ux = roi->ux;
158 ly = roi->ly;
159 uy = roi->uy;
160 rfree((void *) roi);
161
162 irect = mat3_inverse(rect);
163
164 for (x = lx; x < ux; x++)
165 for (y = ly; y < uy; y++)
166 {
167 Vec2 v = {Vec2_id};
168
169 v = vec2_rectify(irect, vec2(x + 0.5, y + 0.5));
170 if (im2->vtype != complex_v)
171 {
172 double g;
173
174 g = im_sub_pixf(im1, vec2_y(v), vec2_x(v));
175 im_put_pixf(g, im2, y, x);
176 } else
177 {
178 Complex g = {Complex_id};
179
180 g = im_sub_pixz(im1, vec2_y(v), vec2_x(v));
181 im_put_pixz(g, im2, y, x);
182 }
183 }
184
185 return (im2);
186 }
187
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.