creating an image file from an ASCII text

K

Karthik

Hi,

I have an ASCII text file which contains 1's,0's and *'s.
The file looks something like this
0 1 1 * 1
1 1 0 * *
* 0 1 0 1

I want to create an image file which shows the 1's in green squares,
0's in red squares and *'s in yellow squares.

I have a ton of these files and would like to create a script which
does the whole process of conversion and dumps out an image file in one
go.

Image files can be in jpeg/gif/png/eps/ps and the script can be in
perl/tcl/c/c++ or any thing else

Is there something out there which does this. Could someone please
help/guide me on this topic.

Thanks
Karthik
 
M

Mike Scott

Karthik said:
Hi,

I have an ASCII text file which contains 1's,0's and *'s.
The file looks something like this
0 1 1 * 1
1 1 0 * *
* 0 1 0 1

I want to create an image file which shows the 1's in green squares,
0's in red squares and *'s in yellow squares.

I have a ton of these files and would like to create a script which
does the whole process of conversion and dumps out an image file in one
go.

Image files can be in jpeg/gif/png/eps/ps and the script can be in
perl/tcl/c/c++ or any thing else

Is there something out there which does this. Could someone please
help/guide me on this topic.

Offhand, I'd look at ImageMagick which is a command-line program (or
rather, suite of) which can create images by tiling component parts (and
also does lots of other good things). Then think about a short script to
read your file of 0/1/* and generate suitable commands to run
ImageMagick appropriately.

Maybe there are prettier ways. The best solution may depend on whether
this is a one-off, or whether you need high efficiency.
 
J

Jean-Claude Arbaut

Offhand, I'd look at ImageMagick which is a command-line program (or
rather, suite of) which can create images by tiling component parts (and
also does lots of other good things). Then think about a short script to
read your file of 0/1/* and generate suitable commands to run
ImageMagick appropriately.

An awk script to convert to ppm, for example ? (awk is just a suggestion,
any other will do).
 
W

Walter Roberson

I have an ASCII text file which contains 1's,0's and *'s.
The file looks something like this
0 1 1 * 1
1 1 0 * *
* 0 1 0 1
I want to create an image file which shows the 1's in green squares,
0's in red squares and *'s in yellow squares.
I have a ton of these files and would like to create a script which
does the whole process of conversion and dumps out an image file in one
go.
Image files can be in jpeg/gif/png/eps/ps and the script can be in
perl/tcl/c/c++ or any thing else

You can encode the files in ppm (portable pixmap file format) and
then convert to another format, such as by using 'ppmtogif' or
a program such as 'xv'.

Or, since perl is one of your options, you could use one of the perl
graphics libraries from cpan.org and do it all in one go.


The below sample encoding script is OT for C, but you can
convert it to C code if you want ;-)


$ cat rgy
#!/bin/ksh

[[ $# -ne 1 ]] && echo "Usage: $0 toppm FILE" >&2 && exit
FID=$1
NFID=$FID.ppm
[[ ! -f "$FID" ]] && echo "Not a readable file: $FID" >&2 && exit
((WID=$(head -1 $FID | wc -c) / 2))
((HIGH=$(wc -l < $FID)))

(
echo "P3"
echo "# $FID converted to ppm format"
echo "$WID $HIGH"
echo "# 1 is the maximum colour intensity"
echo "1"
sed -e 's/0/R/g' -e 's/1/G/g' -e 's/\*/Y/g' \
-e 's/R/1 0 0/g' -e 's/G/0 1 0/g' -e 's/Y/1 1 0/g' $FID | fmt -66
) > $NFID

$ cat testfid
0 1 1 * 1
1 1 0 * *
* 0 1 0 1

$ ./rgy testfid
$ cat testfid.ppm
P3
# testfid converted to ppm format
5 3
# 1 is the maximum colour intensity
1
1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0
1 0 0 0 1 0 1 0 0 0 1 0
 
M

Mark F. Haigh

Karthik wrote:
Image files can be in jpeg/gif/png/eps/ps and the script can be in
perl/tcl/c/c++ or any thing else

Is there something out there which does this. Could someone please
help/guide me on this topic.

This is off-topic in comp.lang.c. Please post image processing
questions elsewhere.


Mark F. Haigh
(e-mail address removed)
 
R

ramachandrank

This can be done easily in Java.

Create an Image buffer and open your ASCII file. Depending on the value
plot the squares and save this buffer to an Image file.

If u want, i can give u the code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top