static void usage ( char *nom )

/******************************************************************************/
/*
  Purpose:
 
    USAGE prints a usage message.

  Reference:
 
    Eric Thiemard,
    An Algorithm to Compute Bounds for the Star Discrepancy,
    Journal of Complexity,
    Volume 17, pages 850-880, 2001.
*/
{
  fprintf(stderr,"Usage : %s s epsilon n Filename Num Den\n",nom);
  fprintf(stderr," Dimension s>=2 integer\n");
  fprintf(stderr," Accuracy parameter 0<epsilon<1\n");
  fprintf(stderr," Number of points n>=1 integer\n");
  fprintf(stderr," Filename (the file must contain at least n points)\n");
  fprintf(stderr," (Optional integer balance parameters Num and Den\n");
  fprintf(stderr,"  such that 0<Num/Den<1. Default is Num=1, Den=2)\n\n");
  fileformat();

  return;
}
Exemple #2
0
/* load PNG, TIFF, JPG, GIF or BMP to PIX datastructure. The actual supported
 * formats depends on how the leptonica was compiled */
PIX *loadimage(char *filename){
    PIX *pix, *pixt;
    int format, bpp;
    format=fileformat(filename);
        // In later versions of leptonica you will have to do this 
        // pixReadHeader(filename, format,NULL,NULL,NULL,bpp,NULL);
    if(format!=IFF_PNG && format!=IFF_JFIF_JPEG && format!=IFF_TIFF && format!=
IFF_GIF && format!=7 && format!=8){
        dfprintf(stderr,"Not recognised file format %i", format);
        return NULL;
    }
    if ((pix = pixRead(filename)) == NULL) return NULL;

/* TODO: convert image to 1-bpp 300dpi regardless of scan */
	bpp=pixGetDepth(pix);
	if(bpp>1){
	/*
		printf("Bits per pixel=%i",bpp);
		exit(1); */
		//pixThresholdForFgBg(pix,5,100,NULL,NULL);
		//pixContrastTRC(pix, pix, 1000);
		pixt = pixContrastNorm(NULL, pix, 10, 10, 40, 2, 2);
		pixDestroy(&pix);
		pix = pixGammaTRC(NULL, pixt, 1.5, 50, 235);
		pixt=pixThresholdToBinary(pix, 200);
		//pixt=pixThreshold8(pix,1,1,0);
		pixDestroy(&pix);
		pix=pixt;
	}
   return pix; 
}
void readfile ( char *filename )

/******************************************************************************/
/*
  Purpose:
 
    READFILE reads the user's input data file.

  Reference:
 
    Eric Thiemard,
    An Algorithm to Compute Bounds for the Star Discrepancy,
    Journal of Complexity,
    Volume 17, pages 850-880, 2001.
*/
{
  int i;
  int j;
  long *tmp;
  char fracreal[256];
  fichier=fopen(filename,"r");
  if (fichier==NULL)
    {
      fprintf(stderr,"PROBLEM: file \"%s\" doesn't exist\n\n",filename);
      fileformat();
    }
  fscanf(fichier,"%d",&i);
  if (i!=s)
    {
      fprintf(stderr,"PROBLEM: this file contains points in dimension %d, not %d\n\n",i,s);
      fileformat();
    }
  fscanf(fichier,"%d",&i);
  if (i<taille)
    {
      fprintf(stderr,"PROBLEM: this file contains only %d (<%d) points\n\n",i,taille);
      fileformat();
    }
  fgets(fracreal,sizeof fracreal,fichier);
  if ((strstr(fracreal,"fractions")==NULL) && (strstr(fracreal,"reals")==NULL))
    fileformat();

  points = (double **) calloc((unsigned) taille,sizeof(double *));
  if (points==NULL)
    memory();
  for (i=0;i<taille;i++)
    {
      points[i] = (double *) calloc((unsigned) s,sizeof(double));
      if (points[i]==NULL)
	memory();
    }

  if (strstr(fracreal,"fractions")!=NULL)
    {
      tmp = (long *) calloc((unsigned) s+1,sizeof(long *));
      for (i=0;i<taille;i++)
	{
	  for (j=0;j<=s;j++)
	    if (fscanf(fichier,"%ld",&tmp[j])==EOF)
	      {
		fprintf(stderr,"PROBLEM: this file contains only %d (<%d) points\n\n",i,taille);
		fileformat();
	      }
	  for (j=0;j<s;j++)
	    {
	      points[i][j] = (double) tmp[j]/tmp[s];
	      if ((points[i][j]<0) || (points[i][j]>1))
		{
		  fprintf(stderr,"PROBLEM: component x(%d,%d) is not in [0,1]\n\n",i+1,j+1);
		  fileformat();
		}
	    }
	}
    }
  else
    {
      for (i=0;i<taille;i++)
	for (j=0;j<s;j++)
	  {
	    if (fscanf(fichier,"%lf",&points[i][j])==EOF)
	      {
		fprintf(stderr,"PROBLEM: this file contains only %d (<%d) points\n\n",i,taille);
		fileformat();
	      }
	    if ((points[i][j]<0) || (points[i][j]>1))
	      {
		fprintf(stderr,"PROBLEM: component x(%d,%d) is not in [0,1]\n\n",i+1,j+1);
		fileformat();
	      }
	  }
    }
  fclose(fichier);

  return;
}