By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

creating an image file from an ASCII text

P: n/a
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

Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Karthik wrote:
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.

--
Please use the corrected version of the address below for replies.
Replies to the header address will be junked, as will mail from
various domains listed at www.scottsonline.org.uk
Mike Scott Harlow Essex England.(unet -a-t- scottsonline.org.uk)
Nov 14 '05 #2

P: n/a
>
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).

Nov 14 '05 #3

P: n/a
In article <11**********************@z14g2000cwz.googlegroups .com>,
Karthik <ks******@gmail.com> wrote:
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
--
Usenet is like a slice of lemon, wrapped around a large gold brick.
Nov 14 '05 #4

P: n/a
Karthik wrote:
<snip>

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
mf*****@sbcglobal.net

Nov 14 '05 #5

P: n/a
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.

Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.