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

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

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

  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 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 General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU 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  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  *
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_grad.c,v $
 27  * Date    :  $Date: 2003/09/26 15:47:09 $
 28  * Version :  $Revision: 1.6 $
 29  * CVS Id  :  $Id: imgPrc_grad.c,v 1.6 2003/09/26 15:47:09 neil Exp $
 30  *
 31  * Author  : Legacy TINA
 32  */
 33 /** 
 34  *  @file
 35  *  @brief Simple image gradient, horizontal and vertical.
 36  * 
 37  *  Functions to calculate simple image gradients in the horizontal and vertical directions 
 38  *  using finite differencing.
 39  */
 40 
 41 #include "imgPrc_grad.h"
 42 
 43 #if HAVE_CONFIG_H
 44 #include <config.h>
 45 #endif
 46 
 47 #include <math.h>
 48 #include <tina/sys/sysDef.h>
 49 #include <tina/sys/sysPro.h>
 50 #include <tina/image/img_GenDef.h>
 51 #include <tina/image/img_GenPro.h>
 52 
 53 /**
 54  * @brief Calculates a simple image gradient in the horizontal direction. 
 55  * @param image The image to calculate gradients from.
 56  * @return grad_im The gradient image.
 57  *
 58  * Calculates simple image gradients in the horizontal direction using finite differencing. For pixels in
 59  * the interior of the image, the gradient is obtained from the two neighbouring pixels in the horizontal 
 60  * direction.  For pixels on the edge of the image, the gradient is obtained from the edge pixel itself and
 61  * its horizontal neighbour. The gradient image is of type float and is allocated here: the original image 
 62  * is not freed.
 63  */
 64 Imrect         *imf_grad_h(Imrect * image)
 65 {
 66         Imrect         *grad_im;
 67         float          *line;
 68         int             lx, ux, ly, uy;
 69         int             uxm1;
 70         int             i, j;
 71 
 72         if (image == NULL)
 73                 return (NULL);
 74 
 75         lx = image->region->lx;
 76         ux = image->region->ux;
 77         ly = image->region->ly;
 78         uy = image->region->uy;
 79         uxm1 = ux - 1;
 80 
 81         grad_im = im_alloc(image->height, image->width, image->region, float_v);
 82         line = fvector_alloc(lx, ux);
 83 
 84         for (i = ly; i < uy; ++i)
 85         {
 86                 im_get_rowf(line, image, i, lx, ux);
 87                 IM_FLOAT(grad_im, i, lx) = line[lx + 1] - line[lx];
 88                 for (j = lx + 1; j < uxm1; ++j)
 89                         IM_FLOAT(grad_im, i, j) = (float) ((line[j + 1] - line[j - 1]) * 0.5);
 90                 IM_FLOAT(grad_im, i, uxm1) = line[uxm1] - line[uxm1 - 1];
 91         }
 92 
 93         fvector_free(line, lx);
 94         return (grad_im);
 95 }
 96 
 97 
 98 /**
 99  * @brief Calculates a simple image gradient in the vertical direction. 
100  * @param image The image to calculate gradients from.
101  * @return grad_im The gradient image.
102  *
103  * Calculates simple image gradients in the vertical direction using finite differencing. For pixels in
104  * the interior of the image, the gradient is obtained from the two neighbouring pixels in the vertical 
105  * direction.  For pixels on the edge of the image, the gradient is obtained from the edge pixel itself and
106  * its vertical neighbour. The gradient image is of type float and is allocated here: the original image 
107  * is not freed.
108  */
109 Imrect         *imf_grad_v(Imrect * image)
110 {
111         Imrect         *grad_im;
112         float          *line;
113         int             lx, ux, ly, uy;
114         int             uym1;
115         int             i, j;
116 
117         if (image == NULL)
118                 return (NULL);
119 
120         lx = image->region->lx;
121         ux = image->region->ux;
122         ly = image->region->ly;
123         uy = image->region->uy;
124         uym1 = uy - 1;
125 
126         grad_im = im_alloc(image->height, image->width, image->region, float_v);
127         line = fvector_alloc(ly, uy);
128 
129         for (i = lx; i < ux; ++i)
130         {
131                 im_get_colf(line, image, i, ly, uy);
132                 IM_FLOAT(grad_im, ly, i) = line[ly + 1] - line[ly];
133                 for (j = ly + 1; j < uym1; ++j)
134                         IM_FLOAT(grad_im, j, i) = (float) ((line[j + 1] - line[j - 1]) * 0.5);
135                 IM_FLOAT(grad_im, uym1, i) = line[uym1] - line[uym1 - 1];
136         }
137 
138         fvector_free(line, ly);
139         return (grad_im);
140 }
141 

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