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_scat.c,v $
37 * Date : $Date: 2005/01/23 19:10:21 $
38 * Version : $Revision: 1.6 $
39 * CVS Id : $Id: imgPrc_scat.c,v 1.6 2005/01/23 19:10:21 paul Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Scatter plot of complex image values and regional inversion for use
47 * in interactive data mining.
48 *
49 */
50
51 #include "imgPrc_scat.h"
52
53 #if HAVE_CONFIG_H
54 #include <config.h>
55 #endif
56
57 #include <math.h>
58 #include <tina/sys/sysDef.h>
59 #include <tina/sys/sysPro.h>
60 #include <tina/math/mathDef.h>
61 #include <tina/math/mathPro.h>
62 #include <tina/image/img_GenDef.h>
63 #include <tina/image/img_GenPro.h>
64 #include <tina/image/imgPrc_apply.h>
65 #define MAXPLOT 255
66
67 Imrect *imz_scat(Imrect * im1, Imregion * roi, float scale)
68 {
69 Imregion *roi2;
70 Imrect *im2;
71 Complex *row1;
72 double pixval, range = (MAXPLOT + 1.0) / scale;
73 int lx, ux, ly, uy;
74 int i, j;
75
76 if (im1 == NULL)
77 return (NULL);
78
79 if (roi == NULL)
80 roi = im1->region;
81 lx = roi->lx;
82 ux = roi->ux;
83 ly = roi->ly;
84 uy = roi->uy;
85
86 im2 = im_alloc(256, 256, NULL, float_v);
87 roi2 = im2->region;
88 row1 = zvector_alloc(lx, ux);
89
90 for (i = ly; i < uy; ++i)
91 {
92 im_get_rowz(row1, im1, i, lx, ux);
93 for (j = lx; j < ux; ++j)
94 {
95 if ((int) (range * row1[j].x) > roi2->lx && (int) (range * row1[j].x) < roi2->ux
96 && (int) (range * row1[j].y) > roi2->ly && (int) (range * row1[j].y) < roi2->uy)
97 {
98 IM_PIX_GET(im2, MAXPLOT - (int) (range * row1[j].y), (int) (range * row1[j].x), pixval);
99 pixval += 1.0;
100 IM_PIX_SET(im2, MAXPLOT - (int) (range * row1[j].y), (int) (range * row1[j].x), pixval);
101 }
102 }
103 }
104
105 zvector_free(row1, lx);
106 return (im2);
107 }
108
109 Imrect *imz_iscat(Imrect * im1, Imrect * im2, Imregion * roi, float scale)
110 {
111 Imregion *roi2;
112 Imrect *im3;
113 Complex *row2;
114 float *row3;
115 double pixval, range = (MAXPLOT + 1.0) / scale;
116 Imrect *im4;
117 int lx, ux, ly, uy;
118 int i, j;
119
120 if (im1 == NULL || im2 == NULL)
121 return (NULL);
122
123 if (roi != NULL)
124 {
125 im4 = im_subim(im1, roi);
126 } else
127 im4 = im_copy(im1);
128 roi = im4->region;
129
130 roi2 = im2->region;
131 lx = roi2->lx;
132 ux = roi2->ux;
133 ly = roi2->ly;
134 uy = roi2->uy;
135
136 im3 = im_alloc(im2->height, im2->width, roi2, float_v);
137 row2 = zvector_alloc(lx, ux);
138 row3 = fvector_alloc(lx, ux);
139
140 for (i = ly; i < uy; ++i)
141 {
142 im_get_rowz(row2, im2, i, lx, ux);
143 for (j = lx; j < ux; ++j)
144 {
145 if ((int) (range * row2[j].x) > roi->lx && (int) (range * row2[j].x) < roi->ux
146 && MAXPLOT - (int) (range * row2[j].y) > roi->ly && MAXPLOT - (int) (range * row2[j].y) < roi->uy)
147 {
148 IM_PIX_GET(im4, MAXPLOT - (int) (range * row2[j].y), (int) (range * row2[j].x), pixval);
149 row3[j] = pixval;
150 } else
151 row3[j] = 0.0;
152 }
153 im_put_rowf(row3, im3, i, lx, ux);
154 }
155
156 zvector_free(row2, lx);
157 fvector_free(row3, lx);
158 im_free(im4);
159 return (im3);
160 }
161
162 static Imrect *normaliser(Imrect * graph_im)
163 {
164 int i, j, ux, lx, uy, ly;
165 float total = 0, pix, new_pix=0;
166 Imrect *norm_graph_im;
167 Imregion *roi;
168
169 norm_graph_im = im_copy(graph_im);
170 roi = graph_im->region;
171 ux = roi->ux;
172 uy = roi->uy;
173 lx = roi->lx;
174 ly = roi->ly;
175
176 for (i = lx; i < ux; i++)
177 {
178 total = 0.0;
179 for (j = ly; j < uy; j++)
180 {
181 total = total + im_get_pixf(graph_im, j, i);
182 }
183 for (j = ly; j < uy; j++)
184 {
185 pix = im_get_pixf(graph_im, j, i);
186 if (total != 0)
187 new_pix = (pix) / (total);
188 im_put_pixf(new_pix, norm_graph_im, j, i);
189 }
190 }
191 return (norm_graph_im);
192 }
193
194 Imrect *imz_dscat(Imrect * graph_im, Imrect * complex_im, Imregion * roi, float scale)
195 {
196 int i, j, k, ux, lx, uy, ly, imux, imlx, imuy, imly;
197 double left_pix, right_pix, subpix;
198 float range = (MAXPLOT + 1.0) / scale;
199 float graph_pix, total, this_pix, prev_pix, next_pix,
200 subfrac;
201 Imrect *left_im, *right_im;
202 Imrect *difference_im, *norm_graph_im;
203 Imregion *imroi;
204
205 left_im = im_re(complex_im);
206 right_im = im_im(complex_im);
207
208 imroi = roi_inter(left_im->region, right_im->region);
209 if (imroi == NULL)
210 return (NULL);
211
212 imlx = imroi->lx;
213 imux = imroi->ux;
214 imly = imroi->ly;
215 imuy = imroi->uy;
216
217 lx = roi->lx;
218 ux = roi->ux;
219 ly = roi->ly;
220 uy = roi->uy;
221
222 difference_im = im_cast(right_im, float_v);
223 norm_graph_im = normaliser(graph_im);
224
225 for (i = imly; i < imuy; i++)
226 {
227 for (j = imlx; j < imux; j++)
228 {
229 left_pix = range * im_get_pixf(left_im, i, j);
230 right_pix = range * im_get_pixf(right_im, i, j);
231 graph_pix = im_sub_pixf(norm_graph_im, MAXPLOT - right_pix, left_pix);
232 subpix = (int) (right_pix) - right_pix;
233 prev_pix = im_sub_pixf(norm_graph_im, ly,
234 (left_pix));
235 this_pix = im_sub_pixf(norm_graph_im, ly + 1.0,
236 (left_pix));
237 total = 0.0;
238 for (k = ly + 1; k < uy - 1; k++)
239 {
240 next_pix = im_sub_pixf(norm_graph_im, k + 1.0,
241 (left_pix));
242 subfrac = fabs((next_pix - prev_pix) / 2.0);
243 if (graph_pix > this_pix + subfrac)
244 {
245 total += this_pix;
246 } else if (graph_pix > this_pix - subfrac)
247 {
248 total += 0.5 * this_pix * (graph_pix - this_pix + subfrac) / subfrac;
249 }
250 prev_pix = this_pix;
251 this_pix = next_pix;
252 }
253 im_put_pixf(total, difference_im, i, j);
254 }
255 }
256
257 im_free(left_im);
258 im_free(right_im);
259 im_free(norm_graph_im);
260
261 return (difference_im);
262 }
263
264 Imrect *im_scat(Imrect * im, Imregion * roi, float scale)
265 {
266 if (im == NULL)
267 return (NULL);
268 switch (im->vtype)
269 {
270 case complex_v:
271 return (imz_scat(im, roi, scale));
272 default:
273 return (NULL);
274 }
275 }
276
277 Imrect *im_iscat(Imrect * im, Imrect * im2, Imregion * roi, float scale)
278 {
279 if (im == NULL || im2 == NULL)
280 return (NULL);
281
282 switch (im2->vtype)
283 {
284 case complex_v:
285 return (imz_iscat(im, im2, roi, scale));
286 default:
287 return (NULL);
288 }
289 }
290
291 Imrect *im_dscat(Imrect * im, Imrect * im2, Imregion * roi, float scale)
292 {
293 if (im == NULL || im2 == NULL)
294 return (NULL);
295
296 switch (im2->vtype)
297 {
298 case complex_v:
299 return (imz_dscat(im, im2, roi, scale));
300 default:
301 return (NULL);
302 }
303 }
304
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.