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_quad.c,v $
37 * Date : $Date: 2003/10/08 15:02:10 $
38 * Version : $Revision: 1.9 $
39 * CVS Id : $Id: imgPrc_quad.c,v 1.9 2003/10/08 15:02:10 neil Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Create a reflection symmetric square image by reflecting the data at the
47 * image edges.
48 *
49 * Subsequent Fourier transforms are then equivalent to a Cosine transform.
50 *
51 */
52
53 /*
54 * Notes : old im_quad written by NAT renamed im_quad2
55 * new un_quad function successfully quads any sized image
56 *
57 *
58 */
59
60 #include "imgPrc_quad.h"
61
62 #if HAVE_CONFIG_H
63 #include <config.h>
64 #endif
65
66 #include <assert.h>
67
68 #include <math.h>
69 #include <tina/sys/sysDef.h>
70 #include <tina/sys/sysPro.h>
71 #include <tina/math/mathDef.h>
72 #include <tina/math/mathPro.h>
73 #include <tina/image/img_GenDef.h>
74 #include <tina/image/img_GenPro.h>
75
76
77 Imrect *im_quad(Imrect * im)
78 {
79 Imrect *im2;
80 Imregion roi;
81 double pixval;
82 int lx, ux, ly, uy;
83 int i, j;
84
85 if (im->vtype == complex_v)
86 return (NULL);
87 roi = *(Imregion *) im->region;
88
89 lx = roi.lx;
90 ux = roi.ux;
91 ly = roi.ly;
92 uy = roi.uy;
93
94 roi.ux += ux - lx;
95 roi.uy += uy - ly;
96
97 im2 = im_alloc(2 * im->height, 2 * im->width, &roi, im->vtype);
98
99 for (i = ly; i < uy; i++)
100 {
101 for (j = lx; j < ux; j++)
102 {
103 IM_PIX_GET(im, i, j, pixval);
104 IM_PIX_SET(im2, i, j, pixval);
105 IM_PIX_SET(im2, i, roi.ux + roi.lx - j - 1, pixval);
106 IM_PIX_SET(im2, roi.uy + roi.ly - i - 1, j, pixval);
107 IM_PIX_SET(im2, roi.uy + roi.ly - i - 1, roi.ux + roi.lx - j - 1, pixval);
108 }
109 }
110 return (im2);
111 }
112
113
114 /**
115 * @brief create a square image from im by reflecting out the original data.
116 * @param im Ptr to Imrect
117 * @return im2 Ptr to Imrect which is square version of im
118 *
119 * The square image is created by expanding the minor dimension to be equal to the
120 * larger dimension by reflecting out the data about the origin. This algorithm
121 * might have problems with images with a factor of 2 or more difference between
122 * height and width.
123 *
124 * a.lacey@man.ac.uk
125 */
126 Imrect *im_square(Imrect * im)
127 {
128 Imrect *im2;
129 Imregion roi;
130 double dimRatio;
131 int lx, ux, ly, uy;
132
133 if (im == NULL || im->vtype == complex_v)
134 return (NULL);
135
136 roi = *(Imregion *) im->region;
137 lx = roi.lx;
138 ux = roi.ux;
139 ly = roi.ly;
140 uy = roi.uy;
141
142 dimRatio = (double)(ux - lx) / (double)(uy - ly);
143 if (dimRatio > 2.0 || dimRatio < 0.5)
144 return (NULL);
145 if (dimRatio == 1.0)
146 return (im_copy(im));
147
148 if (ux - lx > uy - ly)
149 {
150 int i, j, geti;
151 double pixval;
152 double sizeFactor = ((double)(ux - lx) - (double)(uy - ly)) / 2.0;
153
154 roi.ly = ly - floor(sizeFactor);
155 roi.uy = uy + floor(sizeFactor);
156
157 im2 = im_alloc(im->height, im->height, &roi, im->vtype);
158 for (i = roi.ly; i < roi.uy; i++)
159 {
160 if (i < ly)
161 geti = ly + (ly - i);
162 else if (i >= uy)
163 geti = uy + (uy - i) - 1;
164 else
165 geti = i;
166
167 for (j = roi.lx; j < roi.ux; j++)
168 {
169 assert(geti >= ly && geti < uy && j >= lx && j < ux);
170 IM_PIX_GET(im, geti, j, pixval);
171 assert(geti >= roi.ly && geti < roi.uy && j >= roi.lx && j < roi.ux);
172 IM_PIX_SET(im2, i, j, pixval);
173 }
174 }
175 }
176
177 else
178 {
179 int i, j, getj;
180 double pixval;
181 double sizeFactor = ((double)(uy - ly) - (double)(ux - lx)) / 2.0;
182
183 roi.lx = lx - floor(sizeFactor);
184 roi.ux = ux + floor(sizeFactor);
185
186 im2 = im_alloc(im->width, im->width, &roi, im->vtype);
187 for (j = roi.lx; j < roi.ux; j++)
188 {
189 if (j < lx)
190 getj = lx + (lx - j);
191 else if (j >= ux)
192 getj = ux + (ux - j) - 1;
193 else
194 getj = j;
195
196 for (i = roi.ly; i < roi.uy; i++)
197 {
198 assert(i >= ly && i < uy && getj >= lx && getj < ux);
199 IM_PIX_GET(im, i, getj, pixval);
200 assert(i >= roi.ly && i < roi.uy && getj >= roi.lx && getj < roi.ux);
201 IM_PIX_SET(im2, i, j, pixval);
202 }
203 }
204 }
205
206 return (im2);
207 }
208
209
210
211 Imrect *im_quad2(Imrect * im)
212 {
213 Imrect *im2;
214 Imregion roi;
215 double pixval;
216 int lx, ux, ly, uy, nx, ny;
217 int i, j;
218
219 if (im->vtype == complex_v)
220 return (NULL);
221 roi = *(Imregion *) im->region;
222 lx = roi.lx;
223 ux = roi.ux;
224 ly = roi.ly;
225 uy = roi.uy;
226 for (nx = 1; nx <= ux - lx; nx *= 2);
227 for (ny = 1; ny <= uy - ly; ny *= 2);
228 nx /= 2;
229 ny /= 2;
230
231 ux = roi.ux = lx + nx;
232 uy = roi.uy = ly + ny;
233
234 roi.ux += ux - lx;
235 roi.uy += uy - ly;
236
237 im2 = im_alloc(2 * im->height, 2 * im->width, &roi, im->vtype);
238
239 for (i = ly; i < uy; i++)
240 {
241 for (j = lx; j < ux; j++)
242 {
243 IM_PIX_GET(im, i, j, pixval);
244 IM_PIX_SET(im2, i, j, pixval);
245 IM_PIX_SET(im2, i, roi.ux + roi.lx - j - 1, pixval);
246 IM_PIX_SET(im2, roi.uy + roi.ly - i - 1, j, pixval);
247 IM_PIX_SET(im2, roi.uy + roi.ly - i - 1, roi.ux + roi.lx - j - 1, pixval);
248 }
249 }
250 return (im2);
251 }
252
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.