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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgPrc_conv_prof.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_conv_prof.c,v $
 37  * Date    :  $Date: 2009/03/19 18:36:26 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: imgPrc_conv_prof.c,v 1.6 2009/03/19 18:36:26 paul Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief Compute 1D Gaussian convolution profiles
 47  *
 48  */
 49 
 50 #include "imgPrc_conv_prof.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/imgPrc_prof1.h>
 63 
 64 
 65 static double   prof_intg(double x, double s2)
 66 {
 67         float           i, sum = (float) 0.0;
 68         short           tot = 0;
 69 
 70         for (i = (float) (x - 0.5); i <= (float) (x + 0.5); i += (float) 0.1)
 71         {
 72                 sum += (float) exp(-i * i / s2);
 73                 tot++;
 74         }
 75         return (sum / tot);
 76 }
 77 
 78 
 79 static double   prof_g(double x, double s2)
 80 {
 81         return (exp(-x * x / s2));
 82 }
 83 
 84 
 85 Prof1          *prof_gauss_simple(double sig, double precision)
 86 {
 87         float           sig2;
 88         float          *profile;
 89         Prof1          *prof;
 90         int             n, i;
 91 
 92         sig2 = (float) (2.0 * sig * sig);
 93 
 94         for (n = 1;; ++n)
 95                 if (prof_g((double) n, sig2) < precision)
 96                         break;
 97 
 98         prof = prof1_alloc(-n + 1, n, float_v);
 99         profile = prof->el.float_v;
100 
101         for (i = 0; i < n; ++i)
102                 profile[-i] = profile[i] = (float) prof_intg((float) i, sig2);
103         return (prof);
104 }
105 
106 
107 Prof1          *prof_gauss(double sig, double precision)
108 {
109         /* as a ratio of max value */
110 
111         float           sig2, total = (float) 0.0;
112         float          *profile;
113         Prof1          *prof;
114         int             n, i;
115 
116         sig2 = (float) (2.0 * sig * sig);
117 
118         for (n = 1;; ++n)
119                 if (prof_g((double) n, sig2) < precision)
120                         break;
121 
122         if (n > 1000)
123         {
124                 format("gaussian profile limited to length 2000 \n");
125                 n = 1000;
126         }
127 
128         prof = prof1_alloc(-n + 1, n, float_v);
129         profile = prof->el.float_v;
130 
131         for (i = 0; i < n; ++i)
132                 total += profile[-i] = profile[i] = (float) prof_intg((float) i, sig2);
133 
134         total *= 2;
135         total -= profile[0];
136 
137         for (i = -n + 1; i < n; ++i)
138                 profile[-i] /= total;
139 
140         return (prof);
141 }
142 

~ [ 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.