Ejemplo n.º 1
0
Archivo: LLfile.c Proyecto: caomw/mods
static t_LL AuxFile2LL(char * name, int exitOnErr)
{
  char  buffer[MAX_LINE_LENGTH];
  t_LL list  = ConsLL();
  FILE *file = fopen(name,"r");

  if (NULL==file)
    {
      if (!exitOnErr) return list;            /* return empty list */
      else             AbortLL_M("File2LL","can't open file for read");
    }

  while(fgets(buffer,MAX_LINE_LENGTH,file))
    InsLastLLf(list,strlen(buffer)+1,buffer);

  fclose(file);
  return list;
}
Ejemplo n.º 2
0
/*-----------------------------------------------------------------------*/
static t_LL GetList(void)
{
  t_LL list = ConsLL();
  t_LLsize size = Gett_LLsize();
   
  while(size-- > 0)
  {
    t_ELMsize elemSize = Gett_ELMsize();
    if (0 == elemSize )
    {  /* this element is a list, get it by a recursive call */
       t_LL listElem = GetList();
       InsLastLL(list,listElem);
    }
    else
    { 
       void * elemData = InsEmptyBefLLf(list2link(list),elemSize);
       if (1!=fread(elemData,elemSize,1,fileR))
         AbortLL_M("GetList","fread failed");
    }
  }

  return list;
}
   void FastSetOptThresholds4StableRegion(t_region *p_r)
   {
      if (p_r->pixel_total < g_thresh_params.min_size )
         return;

      /* see below quality */
      int invertCons  = (g_thresh_params.invert) ? 255  : 0;
      int invertMulti = (g_thresh_params.invert) ? (-1) : 1;

      int *cummulAreas = p_r->pixels;
      int *cummulBorders = p_r->borders;  

      int i;
      
      /* calculate all cummulative stats */
      for(i=p_r->minimum_int+1; i <= p_r->maximum_int; i++)
      {
         p_r->pixels[i] += p_r->pixels[i-1];
         p_r->borders[i] += p_r->borders[i-1];
      }

      int up, localMaxMargin = -1, localMaxPos = -1;
            
      /* look for threshold that guarantee area bigger than min_size*/
      for(i=p_r->minimum_int; i < p_r->maximum_int; i++)
         if (cummulAreas[i] >= g_thresh_params.min_size) 
            break;

      /* continue with smallest i for which the area is big enough */
      do {
         int area_i = cummulAreas[i]; int radius_i = cummulBorders[i];
               
         /* test from the first acceptable threshold */
         up = int(i + g_thresh_params.min_margin);
               
         if (area_i > g_thresh_params.max_size || up > p_r->maximum_int)
            break;
               
         /* evaluate stability criterion */
         while ((cummulAreas[up] - area_i < radius_i) && (up < p_r->maximum_int)) up++;

         int margin  = up - i;
         double quality = (double) margin;
         if (g_thresh_params.relative_margin)
            quality /= invertCons + invertMulti * (i + (margin/2));
               
         /* non-maximum suppression */
         if (quality > g_thresh_params.min_margin && 
             margin >= localMaxMargin)
         {
            /* if margin are not descending & are higher than 
               min_margin, actualise local maxima position */
            localMaxMargin = margin;
            localMaxPos = i;
         } else {
            /* margin is bellow the min_margin or margin 
               function is descending */
            if (localMaxPos >= 0)
            {
               t_thresh_def t;
               t.pos    = localMaxPos;
               t.margin = localMaxMargin;
               t.thresh = localMaxPos + localMaxMargin/2;
               t.boundary = 0;
               if (p_r->thresholds==0)
                  p_r->thresholds = ConsLL();
               
               InsLastLL(p_r->thresholds, t);
               localMaxPos = -1;
            }                          
            localMaxMargin = margin;
         }
         i++;
      } while (up < p_r->maximum_int);

      /* process last local maximum */
      if (localMaxPos >= 0)
      {
         t_thresh_def t;
         t.pos    = localMaxPos;
         t.margin = localMaxMargin;
         t.thresh = localMaxPos + localMaxMargin/2;
         t.boundary = 0;
         if (p_r->thresholds==0)
            p_r->thresholds = ConsLL();
         InsLastLL(p_r->thresholds, t);
         localMaxMargin = localMaxPos = -1; 
      }
      SuppresOverlappingTresholds4StableRegions(p_r, cummulAreas);
   }