1 /**********
2 *
3 * This file is part of the TINA Open Source Image Analysis Environment
4 * henceforth known as TINA
5 *
6 * TINA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation.
9 *
10 * TINA is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with TINA; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 **********
20 *
21 * Program : TINA
22 * File : $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_grad.c,v $
23 * Date : $Date: 2003/09/26 15:47:09 $
24 * Version : $Revision: 1.6 $
25 * CVS Id : $Id: imgPrc_grad.c,v 1.6 2003/09/26 15:47:09 neil Exp $
26 *
27 * Author : Legacy TINA
28 */
29 /**
30 * @file
31 * @brief Simple image gradient, horizontal and vertical.
32 *
33 * Functions to calculate simple image gradients in the horizontal and vertical directions
34 * using finite differencing.
35 */
36
37 #include "imgPrc_grad.h"
38
39 #if HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #include <math.h>
44 #include <tina/sys/sysDef.h>
45 #include <tina/sys/sysPro.h>
46 #include <tina/image/img_GenDef.h>
47 #include <tina/image/img_GenPro.h>
48
49 /**
50 * @brief Calculates a simple image gradient in the horizontal direction.
51 * @param image The image to calculate gradients from.
52 * @return grad_im The gradient image.
53 *
54 * Calculates simple image gradients in the horizontal direction using finite differencing. For pixels in
55 * the interior of the image, the gradient is obtained from the two neighbouring pixels in the horizontal
56 * direction. For pixels on the edge of the image, the gradient is obtained from the edge pixel itself and
57 * its horizontal neighbour. The gradient image is of type float and is allocated here: the original image
58 * is not freed.
59 */
60 Imrect *imf_grad_h(Imrect * image)
61 {
62 Imrect *grad_im;
63 float *line;
64 int lx, ux, ly, uy;
65 int uxm1;
66 int i, j;
67
68 if (image == NULL)
69 return (NULL);
70
71 lx = image->region->lx;
72 ux = image->region->ux;
73 ly = image->region->ly;
74 uy = image->region->uy;
75 uxm1 = ux - 1;
76
77 grad_im = im_alloc(image->height, image->width, image->region, float_v);
78 line = fvector_alloc(lx, ux);
79
80 for (i = ly; i < uy; ++i)
81 {
82 im_get_rowf(line, image, i, lx, ux);
83 IM_FLOAT(grad_im, i, lx) = line[lx + 1] - line[lx];
84 for (j = lx + 1; j < uxm1; ++j)
85 IM_FLOAT(grad_im, i, j) = (float) ((line[j + 1] - line[j - 1]) * 0.5);
86 IM_FLOAT(grad_im, i, uxm1) = line[uxm1] - line[uxm1 - 1];
87 }
88
89 fvector_free(line, lx);
90 return (grad_im);
91 }
92
93
94 /**
95 * @brief Calculates a simple image gradient in the vertical direction.
96 * @param image The image to calculate gradients from.
97 * @return grad_im The gradient image.
98 *
99 * Calculates simple image gradients in the vertical direction using finite differencing. For pixels in
100 * the interior of the image, the gradient is obtained from the two neighbouring pixels in the vertical
101 * direction. For pixels on the edge of the image, the gradient is obtained from the edge pixel itself and
102 * its vertical neighbour. The gradient image is of type float and is allocated here: the original image
103 * is not freed.
104 */
105 Imrect *imf_grad_v(Imrect * image)
106 {
107 Imrect *grad_im;
108 float *line;
109 int lx, ux, ly, uy;
110 int uym1;
111 int i, j;
112
113 if (image == NULL)
114 return (NULL);
115
116 lx = image->region->lx;
117 ux = image->region->ux;
118 ly = image->region->ly;
119 uy = image->region->uy;
120 uym1 = uy - 1;
121
122 grad_im = im_alloc(image->height, image->width, image->region, float_v);
123 line = fvector_alloc(ly, uy);
124
125 for (i = lx; i < ux; ++i)
126 {
127 im_get_colf(line, image, i, ly, uy);
128 IM_FLOAT(grad_im, ly, i) = line[ly + 1] - line[ly];
129 for (j = ly + 1; j < uym1; ++j)
130 IM_FLOAT(grad_im, j, i) = (float) ((line[j + 1] - line[j - 1]) * 0.5);
131 IM_FLOAT(grad_im, uym1, i) = line[uym1] - line[uym1 - 1];
132 }
133
134 fvector_free(line, ly);
135 return (grad_im);
136 }
137
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.