
/************************************************************************/
/*    IUSPIM     EP RESEAUX DE NEURONES ARTIFICIELS     07/10/96        */
/*                          Claude Touzet                               */
/************************************************************************/
/* FICHIER SOURCE CODAGE.C                                              */
/************************************************************************/
/* Ce fichier realise le codage des fichiers imagetif.txt pour la       */
/* reconnaissance de caracteres manuscrits par reseaux de neurones      */
/* artificiels.                                                         */
/************************************************************************/

#include <stdio.h>
#include <math.h>
#include <string.h>
#define NbDigits 2

/*****************************************************/

void GetDigitInFile()
{
    FILE *fd, *fe;
	int   i, j, n, nl, nInd, class, ii, jj; 
	char  nom_fic[20], d; 
	int   GlobPattern[25] ;
	int   Width, Width1, Length; 
	short TotalPixNb;
	short Imin, Imax, Jmin, Jmax, Count ;
	long  Res;
	int   Digit[50] [100] ;
	
	printf("nom du fichier entree (ex: Image.bec.tif.txt) : ");
	scanf("%s", nom_fic); 
	fd = fopen(nom_fic, "r"); 
	
	printf("nom du fichier sortie (ex: Image.bec.dat) : ");
	scanf("%s", nom_fic); 
	fe = fopen(nom_fic, "w"); 

	class = 0;

while(1)
   {
   
/********************** lit le fichier scanner **************************/

	while (((d = getc(fd)) != EOF) && ((d != '_') && (d != 'X')))
		putchar(d); 
	if (d == EOF) goto exit;
	Width = 0; Length = 0;
	putchar(d);
	while (((d = getc(fd)) != EOF) && ((d == '_') || 
		(d == 'X') || (d == '\n'))) 
		{
		 if (d == '_') Digit[Length][Width] = 0; 
		 else if (d == 'X') Digit[Length][Width] = 1;
		 Width ++;
		 if (d == '\n') 
		  	{
			 Length ++ ; 
		  	 if (Width > 1) Width1 = Width -1; 
		  	 Width = 0;
		  	} 
		 putchar(d);
		}
	if (d == EOF) goto exit;
	Length = Length - 2;
	printf("\n%d   %d\n", Width1, Length);
	
	for (i=0; i<Length; i++)
		{
		 for (j=0; j<Width1; j++)
			 printf("%3d", Digit[i][j]);
		 printf("\n");
		}

/****** Calcul des valeurs de codage du caractere pour le RNA ***********/
	
	TotalPixNb = Length * Width1;
	nInd = 0;
	for (i = 0 ; i < 5 ; i++)
	    {
	    Imin = i * Length/5;
	    Imax = (i + 1) * Length/5;
	    for (j = 0 ; j < 3 ; j++)
	    	{
	    	 Jmin = j * Width1/3;
	    	 Jmax = (j + 1) * Width1/3;
		 Count = 0;
		 for( ii = Imin ; ii < Imax ; ii++ )
			{
			for( jj = Jmin ; jj < Jmax ; jj++ )
		    		if (Digit[ii][jj] )  Count++;
			}
		     Res = 500L * Count / TotalPixNb;
		     GlobPattern[nInd] = (int) Res;
		     nInd++;
		}
	}
	GlobPattern[15] = class; 
	for (i=0; i < 16; i++) {fprintf(fe, "%3d", GlobPattern[i]);}
	fprintf(fe, "\n");
	if (++class >9) class = 0;

   }

exit: ;
fclose(fd);
fclose(fe);

}

/************************* main ************************************/

main ()
{
GetDigitInFile();
}


















































































































































































































































































































































































































































































@
















K





,

w





X











(

;

<

t

u















-

T

`

y

{









'

?

[

\

h

i

r

w

{









/

G

T













&

-

>

g

x















	

	

	'

	G

	X

	\

	]

	

	

	

	

	

	





0


O


W


s


















!

I

o

~








!
~c

















)

5

6

8

9
































































































































































































































































































































































































































!
~




















































































	













H
H



(0CAc


hh







d







'
























OE












B.h

B



@




H
-:StyleWriter 1200








Times


Courier














(
eV
p


Claude

Claude




























































