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_log.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.5 $
39 * CVS Id : $Id: imgPrc_log.c,v 1.5 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Log and exp transform of scalar and complex images. In addition to
47 * the obvious algebraic uses, this is intended for use as a noise stabilising
48 * transform where the noise on the input data is proportional to the data value.
49 *
50 */
51
52 #include "imgPrc_log.h"
53
54 #if HAVE_CONFIG_H
55 #include <config.h>
56 #endif
57
58 #include <math.h>
59 #include <float.h>
60 #include <tina/sys/sysDef.h>
61 #include <tina/sys/sysPro.h>
62 #include <tina/math/mathDef.h>
63 #include <tina/math/mathPro.h>
64 #include <tina/image/img_GenDef.h>
65 #include <tina/image/img_GenPro.h>
66
67 Imrect *imf_log(Imrect * im1)
68 {
69 Imrect *im2;
70 Imregion *roi;
71 float *row1, *row2;
72 int lx, ux, ly, uy;
73 int i, j;
74
75 if (im1 == NULL)
76 return (NULL);
77
78 roi = im1->region;
79 if (roi == NULL)
80 return (NULL);
81 lx = roi->lx;
82 ux = roi->ux;
83 ly = roi->ly;
84 uy = roi->uy;
85
86 im2 = im_alloc(im1->height, im1->width, roi, float_v);
87 row1 = fvector_alloc(lx, ux);
88 row2 = fvector_alloc(lx, ux);
89
90 for (i = ly; i < uy; ++i)
91 {
92 im_get_rowf(row1, im1, i, lx, ux);
93 for (j = lx; j < ux; ++j)
94 if (row1[j] > 0.0)
95 row2[j] = (float) log(row1[j]);
96 else if (row1[j] == 0.0)
97 row2[j] = -FLT_MAX;
98 else
99 row2[j] = (float) log(-row1[j]);
100 im_put_rowf(row2, im2, i, lx, ux);
101 }
102
103 fvector_free(row1, lx);
104 fvector_free(row2, lx);
105 return (im2);
106 }
107
108 Imrect *imz_log(Imrect * im1)
109 {
110 Imrect *im2;
111 Imregion *roi;
112 Complex *row1;
113 Complex *row2;
114 int lx, ux, ly, uy;
115 int i, j;
116
117 if (im1 == NULL)
118 return (NULL);
119
120 roi = im1->region;
121 if (roi == NULL)
122 return (NULL);
123 lx = roi->lx;
124 ux = roi->ux;
125 ly = roi->ly;
126 uy = roi->uy;
127
128 im2 = im_alloc(im1->height, im1->width, roi, complex_v);
129 row1 = zvector_alloc(lx, ux);
130 row2 = zvector_alloc(lx, ux);
131
132 for (i = ly; i < uy; ++i)
133 {
134 im_get_rowz(row1, im1, i, lx, ux);
135 for (j = lx; j < ux; ++j)
136 row2[j] = cmplx_log(row1[j]);
137 im_put_rowz(row2, im2, i, lx, ux);
138 }
139
140 zvector_free(row1, lx);
141 zvector_free(row2, lx);
142 return (im2);
143 }
144
145 Imrect *im_log(Imrect * im)
146 {
147 switch (im->vtype)
148 {
149 case complex_v:
150 return (imz_log(im));
151 default:
152 return (imf_log(im));
153 }
154 }
155
156 Imrect *imf_exp(Imrect * im1)
157 {
158 Imrect *im2;
159 Imregion *roi;
160 float *row1, *row2;
161 int lx, ux, ly, uy;
162 int i, j;
163
164 if (im1 == NULL)
165 return (NULL);
166
167 roi = im1->region;
168 if (roi == NULL)
169 return (NULL);
170 lx = roi->lx;
171 ux = roi->ux;
172 ly = roi->ly;
173 uy = roi->uy;
174
175 im2 = im_alloc(im1->height, im1->width, roi, float_v);
176 row1 = fvector_alloc(lx, ux);
177 row2 = fvector_alloc(lx, ux);
178
179 for (i = ly; i < uy; ++i)
180 {
181 im_get_rowf(row1, im1, i, lx, ux);
182 for (j = lx; j < ux; ++j)
183 row2[j] = (float) exp(row1[j]);
184 im_put_rowf(row2, im2, i, lx, ux);
185 }
186
187 fvector_free(row1, lx);
188 fvector_free(row2, lx);
189 return (im2);
190 }
191
192 Imrect *imz_exp(Imrect * im1)
193 {
194 Imrect *im2;
195 Imregion *roi;
196 Complex *row1;
197 Complex *row2;
198 int lx, ux, ly, uy;
199 int i, j;
200
201 if (im1 == NULL)
202 return (NULL);
203
204 roi = im1->region;
205 if (roi == NULL)
206 return (NULL);
207 lx = roi->lx;
208 ux = roi->ux;
209 ly = roi->ly;
210 uy = roi->uy;
211
212 im2 = im_alloc(im1->height, im1->width, roi, complex_v);
213 row1 = zvector_alloc(lx, ux);
214 row2 = zvector_alloc(lx, ux);
215
216 for (i = ly; i < uy; ++i)
217 {
218 im_get_rowz(row1, im1, i, lx, ux);
219 for (j = lx; j < ux; ++j)
220 row2[j] = cmplx_exp(row1[j]);
221 im_put_rowz(row2, im2, i, lx, ux);
222 }
223
224 zvector_free(row1, lx);
225 zvector_free(row2, lx);
226 return (im2);
227 }
228
229 Imrect *im_exp(Imrect * im)
230 {
231 switch (im->vtype)
232 {
233 case complex_v:
234 return (imz_exp(im));
235 default:
236 return (imf_exp(im));
237 }
238 }
239
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.