473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

creating an image file from an ASCII text

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
5 2907
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
>
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Randy Webb | last post by:
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can have PHP read an image file and out put its color content? Preferably, I would like for it to read a .bmp file and output a...
9
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
0
by: Anonieko Ramos | last post by:
> I have a graphics images that I want to convert to > ASCII art. How do I do it? > Code: - Default.aspx.cs
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
5
by: Socrates | last post by:
I am interested in developing an online utility that will enable users to copy and past any image (or upload any image on the internet) to the online utility, which will then convert the image to...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
3
by: grawsha2000 | last post by:
Hi, I'm trying to convert this simple string into image: Dim bytes() as byte()=System.text.Encoding.ascii.GetBytes("123") Dim memStream as System.IO.MemoryStream Dim img as image ...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.