Ejemplo n.º 1
0
/*************************************************************************
**************************************************************************
#cat: free_path - Traverses a straight line between 2 pixel points in an
#cat:             image and determines if a "free path" exists between the
#cat:             2 points by counting the number of pixel value transitions
#cat:             between adjacent pixels along the trajectory.

   Input:
      x1       - x-pixel coord of first point
      y1       - y-pixel coord of first point
      x2       - x-pixel coord of second point
      y2       - y-pixel coord of second point
      bdata    - binary image data (0==while & 1==black)
      iw       - width (in pixels) of image
      ih       - height (in pixels) of image
      lfsparms - parameters and threshold for controlling LFS
   Return Code:
      TRUE      - free path determined to exist
      FALSE     - free path determined not to exist
      Negative  - system error
**************************************************************************/
int free_path(const int x1, const int y1, const int x2, const int y2,
              unsigned char *bdata, const int iw, const int ih,
              const LFSPARMS *lfsparms)
{
   int *x_list, *y_list, num;
   int ret;
   int i, trans, preval;

   /* Compute points along line segment between the two points. */
   if((ret = line_points(&x_list, &y_list, &num, x1, y1, x2, y2)))
      return(ret);

   /* Intialize the number of transitions to 0. */
   trans = 0;
   /* Get the pixel value of first point along line segment. */
   preval = *(bdata+(y1*iw)+x1);

   /* Foreach remaining point along line segment ... */
   for(i = 1; i < num; i++){
      /* Get pixel value of next point along line segment. */
      int nextval = *(bdata+(y_list[i]*iw)+x_list[i]);

      /* If next pixel value different from previous pixel value ... */
      if(nextval != preval){
         /* Then we have detected a transition, so bump counter. */
         trans++;
         /* If number of transitions seen > than threshold (ex. 2) ... */
         if(trans > lfsparms->maxtrans){
            /* Deallocate the line segment's coordinate lists. */
            free(x_list);
            free(y_list);
            /* Return free path to be FALSE. */
            return(FALSE);
         }
         /* Otherwise, maximum number of transitions not yet exceeded. */
         /* Assign the next pixel value to the previous pixel value.   */
         preval = nextval;
      }
      /* Otherwise, no transition detected this interation. */

   }

   /* If we get here we did not exceed the maximum allowable number        */
   /* of transitions.  So, deallocate the line segment's coordinate lists. */
   free(x_list);
   free(y_list);

   /* Return free path to be TRUE. */
   return(TRUE);
}
Ejemplo n.º 2
0
Archivo: ridges.c Proyecto: Booley/nbis
/*************************************************************************
**************************************************************************
#cat: ridge_count - Takes a pair of minutiae, and counts the number of
#cat:               ridges crossed along the linear trajectory connecting
#cat:               the 2 points in the image.

   Input:
      first     - index of primary minutia
      second    - index of secondary (neighbor) minutia
      minutiae  - list of minutiae
      bdata     - binary image data (0==while & 1==black)
      iw        - width (in pixels) of image
      ih        - height (in pixels) of image
      lfsparms  - parameters and thresholds for controlling LFS
   Return Code:
      Zero or Positive - number of ridges counted
      Negative         - system error
**************************************************************************/
int ridge_count(const int first, const int second, MINUTIAE *minutiae,
                unsigned char *bdata, const int iw, const int ih,
                const LFSPARMS *lfsparms)
{
   MINUTIA *minutia1, *minutia2;
   int i, ret, found;
   int *xlist, *ylist, num;
   int ridge_count, ridge_start, ridge_end;
   int prevpix, curpix;

   minutia1 = minutiae->list[first];
   minutia2 = minutiae->list[second];

   /* If the 2 mintuia have identical pixel coords ... */
   if((minutia1->x == minutia2->x) &&
      (minutia1->y == minutia2->y))
      /* Then zero ridges between points. */
     return(0);

   /* Compute linear trajectory of contiguous pixels between first */
   /* and second minutia points.                                   */
   if((ret = line_points(&xlist, &ylist, &num,
                        minutia1->x, minutia1->y, minutia2->x, minutia2->y))){
      return(ret);
   }

   /* It there are no points on the line trajectory, then no ridges */
   /* to count (this should not happen, but just in case) ...       */
   if(num == 0){
      free(xlist);
      free(ylist);
      return(0);
   }

   /* Find first pixel opposite type along linear trajectory from */
   /* first minutia.                                              */
   prevpix = *(bdata+(ylist[0]*iw)+xlist[0]);
   i = 1;
   found = FALSE;
   while(i < num){
      curpix = *(bdata+(ylist[i]*iw)+xlist[i]);
      if(curpix != prevpix){
         found = TRUE;
         break;
      }
      i++;
   }

   /* If opposite pixel not found ... then no ridges to count */
   if(!found){
      free(xlist);
      free(ylist);
      return(0);
   }

   /* Ready to count ridges, so initialize counter to 0. */
   ridge_count = 0;

   print2log("RIDGE COUNT: %d,%d to %d,%d ", minutia1->x, minutia1->y,
                                               minutia2->x, minutia2->y);

   /* While not at the end of the trajectory ... */
   while(i < num){
      /* If 0-to-1 transition not found ... */
      if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){
         /* Then we are done looking for ridges. */
         free(xlist);
         free(ylist);

         print2log("\n");

         /* Return number of ridges counted to this point. */
         return(ridge_count);
      }
      /* Otherwise, we found a new ridge start transition, so store */
      /* its location (the location of the 1 in 0-to-1 transition). */
      ridge_start = i;

      print2log(": RS %d,%d ", xlist[i], ylist[i]);

      /* If 1-to-0 transition not found ... */
      if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){
         /* Then we are done looking for ridges. */
         free(xlist);
         free(ylist);

         print2log("\n");

         /* Return number of ridges counted to this point. */
         return(ridge_count);
      }
      /* Otherwise, we found a new ridge end transition, so store   */
      /* its location (the location of the 0 in 1-to-0 transition). */
      ridge_end = i;

      print2log("; RE %d,%d ", xlist[i], ylist[i]);

      /* Conduct the validation, tracing the contour of the ridge  */
      /* from the ridge ending point a specified number of steps   */
      /* scanning for neighbors clockwise and counter-clockwise.   */
      /* If the ridge starting point is encounted during the trace */
      /* then we can assume we do not have a valid ridge crossing  */
      /* and instead we are walking on and off the edge of the     */
      /* side of a ridge.                                          */
      ret = validate_ridge_crossing(ridge_start, ridge_end,
                                    xlist, ylist, num, bdata, iw, ih,
                                    lfsparms->max_ridge_steps);

      /* If system error ... */
      if(ret < 0){
         free(xlist);
         free(ylist);
         /* Return the error code. */
         return(ret);
      }

      print2log("; V%d ", ret);

      /* If validation result is TRUE ... */
      if(ret){
         /* Then assume we have found a valid ridge crossing and bump */
         /* the ridge counter.                                        */
         ridge_count++;
      }

      /* Otherwise, ignore the current ridge start and end transitions */
      /* and go back and search for new ridge start.                   */
   }

   /* Deallocate working memories. */
   free(xlist);
   free(ylist);

   print2log("\n");

   /* Return the number of ridges counted. */
   return(ridge_count);
}