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

Linux Cross Reference
Tina4/src/covira/pots.c

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

  1 /*
  2 *
  3 * pots.c
  4 *
  5 * creating potential images and potential forces
  6 *
  7 */
  8 #include <tina/all_tina.h>
  9 #include <tina/brain.h>
 10 #include <tina/brainfuncs.h>
 11 
 12 /*
 13 Returns gradient vector of image at sub-pixel position.
 14 */
 15 Vec2 im_grad_vec2(Imrect * im, Vec2 p)
 16 {
 17     double gx, gy;
 18     double x = vec2_x(p);
 19     double y = vec2_y(p);
 20     gx = 0.5 * (im_sub_pixf(im, y, x + 1.0) - im_sub_pixf(im, y, x - 1.0));
 21     gy = 0.5 * (im_sub_pixf(im, y + 1.0, x) - im_sub_pixf(im, y - 1.0, x));
 22     return (vec2(gx, gy));
 23 }
 24 
 25 /*
 26 Returns Hessian matrix of image at sub-pixel position.
 27 */
 28 Mat2 im_hess_mat2(Imrect * im, Vec2 p)
 29 {
 30     double ixx, ixy, iyy;
 31     double x = vec2_x(p);
 32     double y = vec2_y(p);
 33 
 34     ixx = 0.5 * (im_sub_pixf(im, y, x + 1)
 35                  - 2.0 * im_sub_pixf(im, y, x)
 36                  + im_sub_pixf(im, y, x - 1));
 37     iyy = 0.5 * (im_sub_pixf(im, y + 1, x)
 38                  - 2.0 * im_sub_pixf(im, y, x)
 39                  + im_sub_pixf(im, y - 1, x));
 40     ixy = 0.25 * (im_sub_pixf(im, y + 1, x + 1)
 41                   - im_sub_pixf(im, y + 1, x - 1)
 42                   - im_sub_pixf(im, y - 1, x + 1)
 43                   + im_sub_pixf(im, y - 1, x - 1));
 44     return (mat2(ixx, ixy, ixy, iyy));
 45 }
 46 
 47 /*
 48 Returns Canny grad squared potential at smoothing scale sigma,
 49 scaled to range 0-255.
 50 */
 51 Imrect *canny_pot(Imrect * im, double sigma)
 52 {
 53     Imrect *pot, *im1;
 54 
 55     if (im == NULL)
 56         return (NULL);
 57     im = imf_lsf_smooth(im, sigma);
 58     im1 = imf_sqrgrad(im);
 59     im_free(im);
 60     pot = imf_minus(im1);
 61     im_free(im1);
 62     imf_scale_inplace(pot, 0.0, 255.0);
 63     return (pot);
 64 }
 65 
 66 /*
 67 canny grad squared potential  smoothing scale sigma
 68 potential zero for image values outside w-l, w+l
 69 */
 70 /*
 71 Returns Canny grad squared potential at smoothing scale sigma,
 72 scaled to range 0-255.  Potential is 255 (unattractive) for
 73 areas outside intensity range l-w/2, l+w/2.
 74 */
 75 Imrect *canny_window_pot(Imrect * im, double sigma, double l, double w)
 76 {
 77     Imrect *pot, *im1, *im2;
 78     Imregion *roi;
 79     int x, y;
 80     if (im == NULL)
 81         return (NULL);
 82     im1 = imf_lsf_smooth(im, sigma);
 83     im2 = imf_sqrgrad(im1); im_free(im1);
 84     pot = imf_minus(im2); im_free(im2);
 85     roi = pot->region;
 86     for(x = roi->lx; x < roi->ux; x++)
 87         for(y = roi->ly; y < roi->uy; y++)
 88         {
 89             double g;
 90             IM_PIX_GET(im, y, x, g);
 91             if(g < l-w/2 || g > l+w/2)
 92                 IM_PIX_SET(pot, y, x, 0);
 93         }
 94     imf_scale_inplace(pot, 0.0, 255.0);
 95     return (pot);
 96 }
 97 
 98 /*
 99 Returns potential attracting snake to dark lines, range sigma.
100 */
101 Imrect *dark_pot(Imrect * im, double sigma)
102 {
103     Imrect *pot;
104 
105     if (im == NULL)
106         return (NULL);
107 
108     pot = imf_gauss(im, sigma, 0.001);
109     imf_scale_inplace(pot, 0.0, 255.0);
110     return (pot);
111 }
112 
113 /*
114 Returns potential attracting snake to bright lines, range sigma.
115 */
116 Imrect *light_pot(Imrect * im, double range, double sigma)
117 {
118     Imrect *pot, *im1, *im2;
119 
120     if (im == NULL)
121         return (NULL);
122 
123     im = imf_lsf_smooth(im, 0.5 * sigma);
124     im1 = imf_lsf_smooth(im, 0.5 * sigma);
125     im_free(im);
126 
127     im = imf_lsf_smooth(im1, 0.5 * range);
128     im2 = imf_lsf_smooth(im, 0.5 * range);
129 
130     imf_scale_inplace(im1, 0.0, 191.0);
131     imf_scale_inplace(im2, 0.0, 64.0);
132     pot = im_sum(im1, im2);
133     im_free(im1);
134     im_free(im2);
135     return (pot);
136 }
137 

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