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_fireburn.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.5 $
39 * CVS Id : $Id: imgPrc_fireburn.c,v 1.5 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Fireburn alorithm - grow regions of known pixels values. Alernatively known
47 * as a distance transform, as the resulting image has values which are a function of
48 * the distance from pixels identified in the input data.
49 *
50 *
51 * im_fireburn implments a fireburning alorithm to grow
52 * regions of known pixels values until entire image
53 * is filled with known (non-zero) values.
54 *
55 */
56
57 #include "imgPrc_fireburn.h"
58
59 #if HAVE_CONFIG_H
60 #include <config.h>
61 #endif
62
63 #include <math.h>
64 #include <tina/sys/sysDef.h>
65 #include <tina/sys/sysPro.h>
66 #include <tina/math/mathDef.h>
67 #include <tina/math/mathPro.h>
68 #include <tina/image/img_GenDef.h>
69 #include <tina/image/img_GenPro.h>
70
71 Imrect *im_fireburn(Imrect * im, double low_thresh, double high_thresh)
72 {
73 Imrect *smask = NULL; /* source mask store */
74 Imrect *dmask = NULL; /* destination mask store */
75 Imrect *mask; /* temporary store when pointers are swapped */
76 int row, col; /* loop variables */
77 int burnt; /* fully burnt control variable */
78 Vartype vtype;
79 Imrect *im2;
80 int row_max, row_min, col_max, col_min;
81
82 vtype = im->vtype;
83 im2 = im_cast(im, float_v);
84 im_free(im);
85 im = im2;
86
87 row_max = im->region->uy;
88 row_min = im->region->ly;
89 col_max = im->region->ux;
90 col_min = im->region->lx;
91
92 /* generate the source mask, 1 for a known value, 0 otherwise */
93
94 smask = im_alloc(im->height, im->width, im->region, short_v);
95
96 FOR_IM(im->region, row, col) IM_SHORT(smask, row, col) =
97 (((IM_FLOAT(im, row, col) >= (float) low_thresh) &&
98 (IM_FLOAT(im, row, col) <= (float) high_thresh)) ? 0 : 1);
99
100 /* generate the destination mask, 1 for a known value, 0 otherwise */
101
102 dmask = im_copy(smask);
103
104 /* check to see if image is not already fully burnt */
105
106 burnt = 1;
107
108 FOR_IM(im->region, row, col) burnt = burnt && IM_SHORT(smask, row, col);
109
110 /* fireburn the image */
111
112 while (burnt == 0)
113 {
114 FOR_IM(im->region, row, col)
115 {
116 if (IM_SHORT(smask, row, col) != 0)
117 {
118 IM_SHORT(dmask, row, col) = IM_SHORT(smask, row, col);
119 if ((row + 1 < row_max) && (col + 1 < col_max))
120 if (IM_SHORT(smask, row + 1, col + 1) == 0)
121 {
122 IM_SHORT(dmask, row + 1, col + 1) = 1;
123 IM_FLOAT(im, row + 1, col + 1) = IM_FLOAT(im, row, col);
124 }
125 if (row + 1 < row_max)
126 if (IM_SHORT(smask, row + 1, col) == 0)
127 {
128 IM_SHORT(dmask, row + 1, col) = 1;
129 IM_FLOAT(im, row + 1, col) = IM_FLOAT(im, row, col);
130 }
131 if ((row + 1 < row_max) && (col - 1 >= col_min))
132 if (IM_SHORT(smask, row + 1, col - 1) == 0)
133 {
134 IM_SHORT(dmask, row + 1, col - 1) = 1;
135 IM_FLOAT(im, row + 1, col - 1) = IM_FLOAT(im, row, col);
136 }
137 if (col + 1 < col_max)
138 if (IM_SHORT(smask, row, col + 1) == 0)
139 {
140 IM_SHORT(dmask, row, col + 1) = 1;
141 IM_FLOAT(im, row, col + 1) = IM_FLOAT(im, row, col);
142 }
143 if (col - 1 >= col_min)
144 if (IM_SHORT(smask, row, col - 1) == 0)
145 {
146 IM_SHORT(dmask, row, col - 1) = 1;
147 IM_FLOAT(im, row, col - 1) = IM_FLOAT(im, row, col);
148 }
149 if ((row - 1 >= row_min) && (col + 1 < col_max))
150 if (IM_SHORT(smask, row - 1, col + 1) == 0)
151 {
152 IM_SHORT(dmask, row - 1, col + 1) = 1;
153 IM_FLOAT(im, row - 1, col + 1) = IM_FLOAT(im, row, col);
154 }
155 if (row - 1 >= row_min)
156 if (IM_SHORT(smask, row - 1, col) == 0)
157 {
158 IM_SHORT(dmask, row - 1, col) = 1;
159 IM_FLOAT(im, row - 1, col) = IM_FLOAT(im, row, col);
160 }
161 if ((row - 1 >= row_min) && (col - 1 >= col_min))
162 if (IM_SHORT(smask, row - 1, col - 1) == 0)
163 {
164 IM_SHORT(dmask, row - 1, col - 1) = 1;
165 IM_FLOAT(im, row - 1, col - 1) = IM_FLOAT(im, row, col);
166 }
167 }
168 }
169
170 /* check to see if image is now fully burnt */
171
172 burnt = 1;
173
174 FOR_IM(im->region, row, col) burnt = burnt && IM_SHORT(dmask, row, col);
175
176 /* swap over the source and destination masks */
177
178 mask = dmask;
179 dmask = smask;
180 smask = mask;
181 }
182
183 im = im_cast(im2, vtype);
184 im_free(im2);
185
186 im_free(smask);
187 im_free(dmask);
188
189 return (im);
190 }
191
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.