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_convolve.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.4 $
39 * CVS Id : $Id: imgPrc_convolve.c,v 1.4 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Convolve two images
47 *
48 * im_convolve implements a valid 2D convolution of an image and a
49 * kernel image, new_im is used to store the result, im is
50 * the image to be convolved, both new_im and im should be based
51 * on the same roi
52 *
53 */
54
55 #include "imgPrc_convolve.h"
56
57 #if HAVE_CONFIG_H
58 #include <config.h>
59 #endif
60
61 #include <stdio.h>
62 #include <stdlib.h>
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 void im_convolve(Imrect * new_im, Imrect * im, Imrect * kern)
72 {
73 Imregion *roi; /* temporary roi */
74 int row, col, krow, kcol; /* loop variables */
75 int width, height, lower_x, lower_y, upper_x, upper_y,
76 off_x, off_y;
77
78 width = (int) abs(kern->region->ux - kern->region->lx);
79 height = (int) abs(kern->region->uy - kern->region->ly);
80
81 if ((width % 2) == 0)
82 {
83 lower_x = -(int) (abs(width / 2));
84 upper_x = (int) (abs(width / 2));
85 } else
86 {
87 lower_x = -(int) (abs(width / 2));
88 upper_x = (int) (abs(width / 2)) + 1;
89 }
90 if ((height % 2) == 0)
91 {
92 lower_y = -(int) (abs(height / 2));
93 upper_y = (int) (abs(height / 2));
94 } else
95 {
96 lower_y = -(int) (abs(height / 2));
97 upper_y = (int) (abs(height / 2)) + 1;
98 }
99
100 roi = roi_alloc(lower_x, lower_y, upper_x, upper_y);
101
102 off_x = kern->region->lx - lower_x;
103 off_y = kern->region->ly - lower_y;
104
105 FOR_IM(new_im->region, row, col)
106 {
107 IM_FLOAT(new_im, row, col) = 0.0;
108
109 FOR_IM(roi, krow, kcol)
110 IM_FLOAT(new_im, row, col) +=
111 (IM_FLOAT(im, row + krow, col + kcol) * IM_FLOAT(kern, off_y + krow, off_x + kcol));
112 }
113 }
114
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.