Newsgroups: comp.ai.neural-nets
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!EU.net!Portugal.EU.net!news.rccn.net!news.ip.pt!news.inesc.pt!animal.inescn.pt!news
From: jcard@inescn.pt (Joao Cardoso)
Subject: Re: TIFF to SNNS-Pattern Format?
Content-Type: multipart/mixed;
    boundary="=-=-=__tkn4tMbaMR0hEitlBSX7hPPfs__=-=-="
Message-ID: <Dy5uHD.Kxx@animal.inescn.pt>
Sender: news@animal.inescn.pt (USENET News System)
Nntp-Posting-Host: bart.inescn.pt
Reply-To: jcardoso@inescn.pt
Content-Transfer-Encoding: 8bit
Organization: INESC-Porto, Portugal
X-Newsreader: knews 0.9.8
References: <51p1de$2o4@sparcserver.lrz-muenchen.de>
Mime-Version: 1.0
Date: Mon, 23 Sep 1996 00:53:36 GMT
Lines: 140

--=-=-=__tkn4tMbaMR0hEitlBSX7hPPfs__=-=-=

In article <51p1de$2o4@sparcserver.lrz-muenchen.de>,
	Edgar Kraus <edgar> writes:
| Hi,
| I am working with the Stuttgart Neural Network Simulator ( SNNS ) and I would
| like to know if anybody knows where I can get a convertiontool to get a TIFF
| image( or other common format ) to the SNNS-patternformat. 
| 
| Thanks,
| Edgar
| 

Try this, if you can convert your tiff imagge to color xpm, e.g. with 'xv'.
Each color will be converted to an output label.
Try first with small images...

Good luck,
Joao

-- 
Joao Cardoso, INESC  |  e-mail: jcardoso@inescn.pt
R. Jose Falcao 110   |  tel:    + 351 2 2094345
4000 Porto, Portugal |  fax:    + 351 2 2008487
--=-=-=__tkn4tMbaMR0hEitlBSX7hPPfs__=-=-=
Content-Type: text/plain
Content-Disposition: attachment; filename="xpm2cluster.c"

/*
	reads a .xpm file (created for example with xpaint)
	and writes the x and y coordinates of each point set, together
	with the point (converted to a number);
	This eases the generation on cluster data, for further analysys.
	The output format is SNNS compatible.

	use: xpm2cluster in_file -no_out -no_lab > out_file

	v1.0	up to 64 clusters;

*/

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

char f_title[] = "SNNS pattern definition file V3.2 \ngenerated at %s\n";
char f_pat[] = "No. of patterns : %d\n";
char f_units[] = "No. of input units : 2\n";
char f_out[] = "No. of output units : 1\n";

main(int argc, char **argv)
{
	FILE*fd;
	char	line[1024], sym[64], c, *tmp;
	int	xdim, ydim, n_clus, pat, no_out=0, no_lab=0;
	int	i,j;
	time_t	clock;
	long	pos;

	if (argc < 2)
	{
		fprintf(stderr,"Use: xpm2cluster [-no_out (output units)] [-no_lab (labels)] in_file > out_file\n");
		exit(0);
	}

	for (i=1; i<argc; i++)
	{
		if (argv[i][0] != '-' && (fd = fopen(argv[i], "r")) == NULL)
		{
			fprintf(stderr, "Unable to open file %s\n", argv[i]);
			exit(0);
		}
			
		else if (strcmp(argv[i], "-no_out") == 0)
			no_out = 1;
			
		else if (strcmp(argv[i], "-no_lab") == 0)
			no_lab = 1;			
	}

	fgets(line, sizeof(line), fd);	/* header XPM... */
	fgets(line, sizeof(line), fd);	/* header static... */
	fgets(line, sizeof(line), fd);	/* xdim, ydim, ncluster, ...*/
	sscanf(line,"%*1s%d%d%d", &xdim, &ydim, &n_clus);

	fgets(line, sizeof(line), fd);	/* jumps over background color */
	n_clus--;
	
	for(i=0; i<n_clus; i++)	
	{
		fgets(line, sizeof(line), fd);
		sscanf(line,"%*1s%c", &sym[i]);
	}
	sym[i] = '\0';

	pos = ftell(fd);
	pat = 0;
	
	for (i=0; i<ydim; i++)
	{
		fgets(line, sizeof(line), fd);
		for (j=0; j<xdim; j++)
		{
			sscanf(line+j+1,"%c", &c);
			if (strchr(sym, c))
				pat++;
		}
	}

	clock = time((time_t *) NULL);
	printf(f_title,(char *) ctime(&clock));
	printf(f_pat, pat-1);
	printf(f_units);
	if (! no_out)
		printf(f_out);

	fseek(fd, pos, SEEK_SET);
	pat = 0;
	for (i=0; i<ydim; i++)
	{
		fgets(line, sizeof(line), fd);
		for (j=0; j<xdim; j++)
		{
			sscanf(line+j+1,"%c", &c);
			if (tmp = strchr(sym, c))
			{
				pat++;
				if (!no_lab)
					printf("#pattern: %d\n", pat);
					
				if (no_out)
					printf("%d %d\n", j, i);
				else 
					printf("%d %d\t%d\n", j, i, tmp - sym);
			}
		}
	}
}
--=-=-=__tkn4tMbaMR0hEitlBSX7hPPfs__=-=-=--
