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

Linux Cross Reference
TINA5/tina-libs/tina/image/imgPrc_conv_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_conv_1d.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: imgPrc_conv_1d.c,v 1.4 2003/09/22 16:09:02 tony Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief Separable convolution functions.
 47  *    
 48  * Use `Faltung' convolution convention:
 49  * (func*prof)[i] = Sum func[i-j]*prof[j]
 50  *
 51  * func is set to 0 when undefined (see smooth.c for another
 52  * convention at limits)
 53  * accepts only floating point convolution profiles
 54  *
 55  * conv_line:
 56 
 57  * Convolves array line1 into line2.
 58  * Upper and lower array limits are for line2.
 59  * Line1 is assumed to be long enough for prof to go off end of line2.
 60  */
 61 
 62 #include "imgPrc_conv_1d.h"
 63 
 64 #if HAVE_CONFIG_H
 65 #include <config.h>
 66 #endif
 67 
 68 #include <math.h>
 69 #include <tina/sys/sysDef.h>
 70 #include <tina/sys/sysPro.h>
 71 #include <tina/math/mathDef.h>
 72 #include <tina/math/mathPro.h>
 73 #include <tina/image/img_GenDef.h>
 74 #include <tina/image/img_GenPro.h>
 75 
 76 static void     conv_line(float *line1, Prof1 * prof, int lower, int upper, float *line2)
 77 {
 78         int             i, j;
 79         int             n1, n2;
 80         double          sum;
 81         float          *el = prof->el.float_v;
 82 
 83         n1 = prof->n1;
 84         n2 = prof->n2;
 85         for (i = lower; i < upper; i++)
 86         {
 87                 sum = 0.0;
 88                 for (j = n1; j < n2; j++)
 89                         sum += line1[i - j] * el[j];
 90                 line2[i] = (float) sum;
 91         }
 92 }
 93 
 94 Imrect         *im_conv_h(Imrect * im1, Prof1 * prof)
 95 {
 96         Imrect         *im2;
 97         Imregion       *roi;
 98         float          *row1, *row2;
 99         int             lx, ux, ly, uy;
100         int             lxn, uxn;
101         int             n1, n2;
102         int             i;
103 
104         if (im1 == NULL)
105                 return (NULL);
106         if (prof == NULL)
107                 return (NULL);
108 
109         if ((roi = im1->region) == NULL)
110                 return (NULL);
111 
112         lx = roi->lx;
113         ux = roi->ux;
114         ly = roi->ly;
115         uy = roi->uy;
116 
117         n1 = prof->n1;
118         n2 = prof->n2;
119         lxn = MAX(lx, lx - n2 + 1);
120         uxn = MIN(ux, ux - n1);
121 
122         im2 = im_alloc(im1->height, im1->width, roi, float_v);
123 
124         row1 = fvector_alloc(lx - n2 + 1, ux - n1);
125         row2 = fvector_alloc(lx, ux);
126 
127         for (i = ly; i < uy; ++i)
128         {
129                 im_get_rowf(row1, im1, i, lxn, uxn);
130                 conv_line(row1, prof, lx, ux, row2);
131                 im_put_rowf(row2, im2, i, lx, ux);
132         }
133 
134         fvector_free(row1, lx - n2 + 1);
135         fvector_free(row2, lx);
136         return (im2);
137 }
138 
139 Imrect         *im_conv_v(Imrect * im1, Prof1 * prof)
140 {
141         Imrect         *im2;
142         Imregion       *roi;
143         float          *col1, *col2;
144         int             lx, ux, ly, uy;
145         int             lyn, uyn;
146         int             n1, n2;
147         int             i;
148 
149         if (im1 == NULL)
150                 return (NULL);
151         if (prof == NULL)
152                 return (NULL);
153 
154         if ((roi = im1->region) == NULL)
155                 return (NULL);
156 
157         lx = roi->lx;
158         ux = roi->ux;
159         ly = roi->ly;
160         uy = roi->uy;
161 
162         n1 = prof->n1;
163         n2 = prof->n2;
164         lyn = MAX(ly, ly - n2 + 1);
165         uyn = MIN(uy, uy - n1);
166 
167         im2 = im_alloc(im1->height, im1->width, roi, float_v);
168 
169         col1 = fvector_alloc(ly - n2 + 1, uy - n1);
170         col2 = fvector_alloc(ly, uy);
171         for (i = lx; i < ux; ++i)
172         {
173                 im_get_colf(col1, im1, i, lyn, uyn);
174                 conv_line(col1, prof, ly, uy, col2);
175                 im_put_colf(col2, im2, i, ly, uy);
176         }
177 
178         fvector_free(col1, ly - n2 + 1);
179         fvector_free(col2, ly);
180         return (im2);
181 }
182 
183 Imrect         *im_conv_separable(Imrect * im1, Prof1 * prof_h, Prof1 * prof_v)
184 {
185         Imrect         *im2;
186         Imrect         *im3;
187 
188         if (im1 == NULL)
189                 return (NULL);
190         if (prof_h == NULL)
191                 return (NULL);
192         if (prof_v == NULL)
193                 return (NULL);
194 
195         im2 = im_conv_h(im1, prof_h);
196         im3 = im_conv_v(im2, prof_v);
197 
198         im_free(im2);
199         return (im3);
200 }
201 

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