Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > creating an image file from an ASCII text

Reply
Thread Tools

creating an image file from an ASCII text

 
 
Karthik
Guest
Posts: n/a
 
      06-15-2005
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

 
Reply With Quote
 
 
 
 
Mike Scott
Guest
Posts: n/a
 
      06-15-2005
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)
 
Reply With Quote
 
 
 
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-15-2005
>
> 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).

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      06-15-2005
In article <(E-Mail Removed) .com>,
Karthik <(E-Mail Removed)> 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.
 
Reply With Quote
 
Mark F. Haigh
Guest
Posts: n/a
 
      06-16-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
ramachandrank@gmail.com
Guest
Posts: n/a
 
      06-18-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser Converts No ASCII for JS Text Node or any Text Attribute vunet.us@gmail.com Javascript 3 06-29-2007 04:28 PM
Regex with ASCII and non-ASCII chars TOXiC Python 5 01-31-2007 04:48 PM
[FR/EN] how to convert the characters ASCII(0-255) to ASCII(0-127) Alextophi Perl Misc 8 12-30-2005 10:43 AM
Question about reading a big binary file and write it into several text (ascii) files Albert Tu Python 2 01-25-2005 03:56 AM
routine/module to translate microsoft extended ascii to plain ascii James O'Brien Perl Misc 3 03-05-2004 04:33 PM



Advertisments