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_hist.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.5 $
39 * CVS Id : $Id: imgPrc_hist.c,v 1.5 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Histogram the contents of an image and generate a frequency of occurence image.
47 *
48 */
49
50 #include "imgPrc_hist.h"
51
52 #if HAVE_CONFIG_H
53 #include <config.h>
54 #endif
55
56 #include <math.h>
57 #include <tina/sys/sysDef.h>
58 #include <tina/sys/sysPro.h>
59 #include <tina/math/mathDef.h>
60 #include <tina/math/mathPro.h>
61 #include <tina/image/img_GenDef.h>
62 #include <tina/image/img_GenPro.h>
63
64 Imrect *imc_hist(shistogram ** imhist, double k, double range,
65 Imrect * im, Imregion * roi)
66 {
67 Imrect *im2;
68 int *row1, *row2;
69 int lx, ux, ly, uy;
70 int width, height;
71 int i, j;
72
73 if (im == NULL)
74 return (NULL);
75
76 if (roi == NULL)
77 return (NULL);
78 lx = roi->lx;
79 ux = roi->ux;
80 ly = roi->ly;
81 uy = roi->uy;
82
83 width = im->width;
84 height = im->height;
85
86 im2 = im_alloc(height, width, im->region, char_v);
87 if (*imhist == NULL)
88 *imhist = hbook1(0, "image contents\0", (float) (k - range),
89 (float) (k + range), 100);
90
91 row1 = ivector_alloc(lx, ux);
92
93 for (i = ly; i < uy; ++i)
94 {
95 im_get_row(row1, im, i, lx, ux);
96 for (j = lx; j < ux; ++j)
97 {
98 if (row1[j] != 0.0)
99 hfill1s(*imhist, (float) row1[j], 1.0);
100 }
101 }
102
103 ivector_free(row1, lx);
104 roi = im->region;
105 lx = roi->lx;
106 ux = roi->ux;
107 ly = roi->ly;
108 uy = roi->uy;
109 row1 = ivector_alloc(lx, ux);
110 row2 = ivector_alloc(lx, ux);
111 for (i = ly; i < uy; ++i)
112 {
113 im_get_row(row1, im, i, lx, ux);
114 for (j = lx; j < ux; ++j)
115 {
116 row2[j] = hfill1s(*imhist, (float) row1[j], 0.0);
117 }
118 im_put_row(row2, im2, i, lx, ux);
119 }
120
121 ivector_free(row1, lx);
122 ivector_free(row2, lx);
123 return (im2);
124 }
125
126 Imrect *imi_hist(shistogram ** imhist, double k, double range,
127 Imrect * im, Imregion * roi)
128 {
129 Imrect *im2;
130 int *row1, *row2;
131 int lx, ux, ly, uy;
132 int width, height;
133 int i, j;
134
135 if (im == NULL)
136 return (NULL);
137
138 if (roi == NULL)
139 return (NULL);
140 lx = roi->lx;
141 ux = roi->ux;
142 ly = roi->ly;
143 uy = roi->uy;
144
145 width = im->width;
146 height = im->height;
147
148 im2 = im_alloc(height, width, im->region, int_v);
149 if (*imhist == NULL)
150 *imhist = hbook1(0, "image contents\0", (float) (k - range),
151 (float) (k + range), 100);
152
153 row1 = ivector_alloc(lx, ux);
154
155 for (i = ly; i < uy; ++i)
156 {
157 im_get_row(row1, im, i, lx, ux);
158 for (j = lx; j < ux; ++j)
159 {
160 if (row1[j] != 0.0)
161 hfill1s(*imhist, (float) row1[j], 1.0);
162 }
163 }
164
165 ivector_free(row1, lx);
166 roi = im->region;
167 lx = roi->lx;
168 ux = roi->ux;
169 ly = roi->ly;
170 uy = roi->uy;
171 row1 = ivector_alloc(lx, ux);
172 row2 = ivector_alloc(lx, ux);
173 for (i = ly; i < uy; ++i)
174 {
175 im_get_row(row1, im, i, lx, ux);
176 for (j = lx; j < ux; ++j)
177 {
178 row2[j] = hfill1s(*imhist, (float) row1[j], 0.0);
179 }
180 im_put_row(row2, im2, i, lx, ux);
181 }
182
183 ivector_free(row1, lx);
184 ivector_free(row2, lx);
185 return (im2);
186 }
187
188 Imrect *imf_hist(shistogram ** imhist, double k, double range,
189 Imrect * im, Imregion * roi)
190 {
191 Imrect *im2;
192 float *row1, *row2;
193 int lx, ux, ly, uy;
194 int width, height;
195 int i, j;
196
197 if (im == NULL)
198 return (NULL);
199
200 if (roi == NULL)
201 return (NULL);
202 lx = roi->lx;
203 ux = roi->ux;
204 ly = roi->ly;
205 uy = roi->uy;
206
207 width = im->width;
208 height = im->height;
209
210 im2 = im_alloc(height, width, im->region, float_v);
211 if (*imhist == NULL)
212 *imhist = hbook1(0, "image contents\0", (float) (k - range),
213 (float) (k + range), 100);
214
215 row1 = fvector_alloc(lx, ux);
216
217 for (i = ly; i < uy; ++i)
218 {
219 im_get_rowf(row1, im, i, lx, ux);
220 for (j = lx; j < ux; ++j)
221 {
222 if (row1[j] != 0.0)
223 hfill1s(*imhist, (float) row1[j], 1.0);
224 }
225 }
226
227 fvector_free(row1, lx);
228 roi = im->region;
229 lx = roi->lx;
230 ux = roi->ux;
231 ly = roi->ly;
232 uy = roi->uy;
233 row1 = fvector_alloc(lx, ux);
234 row2 = fvector_alloc(lx, ux);
235 for (i = ly; i < uy; ++i)
236 {
237 im_get_rowf(row1, im, i, lx, ux);
238 for (j = lx; j < ux; ++j)
239 {
240 row2[j] = hfill1s(*imhist, (float) row1[j], 0.0);
241 }
242 im_put_rowf(row2, im2, i, lx, ux);
243 }
244
245 fvector_free(row1, lx);
246 fvector_free(row2, lx);
247 return (im2);
248 }
249
250
251 Imrect *im_hist(shistogram ** imhist, double k, double range,
252 Imrect * im, Imregion * roi)
253 {
254 if (im == NULL)
255 return (NULL);
256 switch (im->vtype)
257 {
258 case uchar_v:
259 case char_v:
260 return (imc_hist(imhist, k, range, im, roi));
261 case short_v:
262 case ushort_v:
263 case int_v:
264 return (imi_hist(imhist, k, range, im, roi));
265 case float_v:
266 return (imf_hist(imhist, k, range, im, roi));
267 default:
268 return (NULL);
269 }
270 }
271
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.