~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/image/imgPrc_smooth_1d.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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_smooth_1d.c,v $
 37  * Date    :  $Date: 2009/03/19 18:36:26 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: imgPrc_smooth_1d.c,v 1.5 2009/03/19 18:36:26 paul Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief One dimensional smoothing function
 47  *
 48  * smoothing is a special form of convolution in which edge effects can be
 49  * approximated using sub-total ratios.
 50  *
 51  * functions accept only  floating point covolution profiles
 52  */
 53 
 54 #include "imgPrc_smooth_1d.h"
 55 
 56 #if HAVE_CONFIG_H
 57 #include <config.h>
 58 #endif
 59 
 60 #include <math.h>
 61 #include <tina/sys/sysDef.h>
 62 #include <tina/sys/sysPro.h>
 63 #include <tina/math/mathDef.h>
 64 #include <tina/math/mathPro.h>
 65 #include <tina/image/img_GenDef.h>
 66 #include <tina/image/img_GenPro.h>
 67 #include <tina/image/imgPrc_prof1.h>
 68 
 69 static Prof1   *prof1_subtot_ratio(Prof1 * profile)
 70 {
 71         Prof1          *subtot;
 72         int             i, n1, n2;
 73         float           tot = (float) 0.0;
 74 
 75         n1 = profile->n1;
 76         n2 = profile->n2;
 77         subtot = prof1_alloc(n1, n2, float_v);
 78 
 79         for (i = n1; i < n2; ++i)
 80         {
 81                 subtot->el.float_v[i] = tot;
 82                 tot += profile->el.float_v[i];
 83         }
 84         for (i = n1; i < n2; ++i)
 85                 subtot->el.float_v[i] /= tot;
 86         return (subtot);
 87 }
 88 
 89 void            smooth_1d(float *line, int n1, int n2, Prof1 * profile) /* use profile forwards */
 90 {
 91         float           sum;
 92         int             i, j;
 93         int             p1, p2, firstfull, lastfull;
 94         float          *prof, *subtot;
 95         Prof1          *subtot_p;
 96         float          *temp;
 97 
 98         if (profile == NULL || profile->vtype != float_v)
 99                 return;
100 
101         p1 = profile->n1;
102         p2 = profile->n2;
103         firstfull = MAX(n1 - p1, n1);
104         lastfull = MIN(n2 - p2, n2);
105         prof = profile->el.float_v;
106         subtot_p = prof1_subtot_ratio(profile);
107         subtot = subtot_p->el.float_v;
108         temp = fvector_alloc(n1, n2);
109 
110         for (i = n1; i < firstfull; ++i)
111         {
112                 for (sum = (float) 0.0, j = n1 - i; j < p2; ++j)
113                         sum += prof[j] * line[i + j];
114                 temp[i] = (float) (sum / (1.0 - subtot[n1 - i]));
115         }
116 
117         for (; i <= lastfull; ++i)      /* most work */
118         {
119                 for (sum = (float) 0.0, j = p1; j < p2; ++j)
120                         sum += (float) (prof[j] * line[i + j]);
121                 temp[i] = sum;
122         }
123 
124         for (; i < n2; ++i)
125         {
126                 for (sum = (float) 0.0, j = p1; j < n2 - i; ++j)
127                         sum += prof[j] * line[i + j];
128                 temp[i] = sum / subtot[n2 - i];
129         }
130 
131         for (i = n1; i < n2; ++i)
132                 line[i] = temp[i];
133 
134         fvector_free(temp, n1);
135         prof1_free(subtot_p);
136 }
137 
138 void            smooth_1d_sym(float *line, int n1, int n2, Prof1 * profile)     /* use profile
139                                                                                  * symetrically */
140 {
141         float           sum;
142         int             i, j;
143         int             p1, p2, firstfull, lastfull;
144         int             offset, pm, odd;
145         float          *prof, *subtot;
146         Prof1          *subtot_p;
147         float          *temp;
148 
149         if (profile == NULL || profile->vtype != float_v)
150                 return;
151 
152         p1 = profile->n1;
153         p2 = profile->n2;
154         firstfull = MAX(n1 - p1, n1);
155         lastfull = MIN(n2 - p2, n2);
156         prof = profile->el.float_v;
157         subtot_p = prof1_subtot_ratio(profile);
158         subtot = subtot_p->el.float_v;
159         temp = fvector_alloc(n1, n2);
160 
161         odd = (p2 - p1) % 2;    /* is the profile odd or even */
162         pm = p1 + (p2 - p1) / 2;/* mid point of profile */
163         offset = p1 + p2 - 1;
164 
165         for (i = n1; i < firstfull; ++i)
166         {
167                 for (sum = (float) 0.0, j = n1 - i; j < p2; ++j)
168                         sum += (float) (prof[j] * line[i + j]);
169                 temp[i] = (float) (sum / (1.0 - subtot[n1 - i]));
170         }
171 
172         for (; i <= lastfull; ++i)      /* most work so exploit symetry */
173         {
174                 sum = (odd) ? prof[pm] * line[i + pm] : 0;
175                 for (j = p1; j < pm; ++j)
176                         sum += prof[j] * (line[i + j] + line[i + offset - j]);
177                 temp[i] = sum;
178         }
179 
180         for (; i < n2; ++i)
181         {
182                 for (sum = (float) 0.0, j = p1; j < n2 - i; ++j)
183                         sum += prof[j] * line[i + j];
184                 temp[i] = sum / subtot[n2 - i];
185         }
186 
187         for (i = n1; i < n2; ++i)
188                 line[i] = temp[i];
189 
190         fvector_free(temp, n1);
191         prof1_free(subtot_p);
192 }
193 
194 void            conv_1d(float *line, int n1, int n2, Prof1 * profile)   /* use profile backwards */
195 {
196         float           sum;
197         int             i, j;
198         int             p1, p2;
199         int             lower, upper;
200         float          *prof;
201         float          *temp;
202 
203         if (profile == NULL || profile->vtype != float_v)
204                 return;
205 
206         p1 = profile->n1;
207         p2 = profile->n2;
208         lower = MAX(n1 - p2 + 1, 0);
209         upper = MIN(n2 - p1, n2);
210         prof = profile->el.float_v;
211         temp = fvector_alloc(n1, n2);
212 
213         for (i = n1; i < lower; ++i)
214                 temp[i] = (float) 0.0;
215 
216         for (; i <= upper; ++i) /* most work */
217         {
218                 for (sum = (float) 0.0, j = p1; j < p2; ++j)
219                         sum += prof[j] * line[i - j];
220                 temp[i] = sum;
221         }
222 
223         for (; i < n2; ++i)
224                 temp[i] = (float) 0.0;
225 
226         for (i = n1; i < n2; ++i)
227                 line[i] = temp[i];
228 
229         fvector_free(temp, n1);
230 }
231 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.