473,386 Members | 1,828 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,386 software developers and data experts.

Cellular automata and image manipulation

Hello. I have recently been experimenting with cellular automata and I
would like to know how I could convert a 2d list of 0's and 1's into
white and black squares on an image. I have tried to install matplotlib
and also NumTut but both to no avail. There seem to be bugs in their
installation and I have not been able to figure out how to resolve
them. I would be happy for someone to suggest a library and maybe give
a simple example of how to do what I want to do.

May 13 '06 #1
7 2849
de*****@gmail.com wrote:
Hello. I have recently been experimenting with cellular automata and I
would like to know how I could convert a 2d list of 0's and 1's into
white and black squares on an image. I have tried to install matplotlib
and also NumTut but both to no avail. There seem to be bugs in their
installation and I have not been able to figure out how to resolve
them. I would be happy for someone to suggest a library and maybe give
a simple example of how to do what I want to do.


Why don't you explain your problems with installing numpy (the Numeric Tutorial
is out of date; don't bother with NumTut) or matplotlib on the appropriate
mailing lists?

http://lists.sourceforge.net/lists/l...mpy-discussion
http://lists.sourceforge.net/lists/l...tplotlib-users

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

May 13 '06 #2

<de*****@gmail.com> wrote in message
news:11**********************@d71g2000cwd.googlegr oups.com...
Hello. I have recently been experimenting with cellular automata and I
would like to know how I could convert a 2d list of 0's and 1's into
white and black squares on an image. I have tried to install matplotlib
and also NumTut but both to no avail. There seem to be bugs in their
installation and I have not been able to figure out how to resolve
them. I would be happy for someone to suggest a library and maybe give
a simple example of how to do what I want to do.

In my 1d cellular automaton, I used the python image library and
import Image
nim = Image.new("1", (height * 2, height))
nim.putdata(bimg)
nim.resize((400,200)).save("output.png")

where bimg is a 2d list of 0's and 1's. You could probably remove the
resize.
May 14 '06 #3
Thank you very much. That is highly simple, useful and it works.

May 14 '06 #4
It seemed to work with a 1d list but not with 2d.

May 14 '06 #5
import Image
x = []
buff = []

buff = [[0 for y in range(41)] for x in range(21)]
buff[0][(len(buff)-1)/2] = 1
def rule1():
for i in range(len(buff)-1):
for j in range(len(buff[0])-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[i][j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff[0])-1:
if buff[i][j-1] == 1:
buff[i+1][j] = 1
elif buff[i][j-1] == 1:
buff[i+1][j] = 1
elif buff[i][j+1] == 1:
buff[i+1][j] = 1

def rule2():
for i in range(len(buff)-1):
for j in range(len(buff[0])-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[i][j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff[0])-1:
buff[i+1][j] = 1
elif buff[i][j-1] == 1 and buff[i][j+1] != 1:
buff[i+1][j] = 1
elif buff[i][j+1] == 1 and buff[i][j-1] != 1:
buff[i+1][j] = 1
rule2()
nim = Image.new("1", (400,600))
nim.putdata(buff)
nim.resize((400,600)).save("output.png")

for a in buff:
for x in a:
if x == 1:
print "X",
else: print " ",
print ""

That is my code. Could you tell me what maybe is wrong? Rule2 makes the
fibonacci triangle btw.

May 14 '06 #6
Sorry this is the latest, the previous didn't work so well:

import Image
x = []
buff = []

buff = [[0 for y in range(41)] for x in range(21)]
buff[0][(len(buff[0])-1)/2] = 1
def rule1():
for i in range(len(buff)-1):
for j in range(len(buff[0])-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[i][j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff[0])-1:
if buff[i][j-1] == 1:
buff[i+1][j] = 1
elif buff[i][j-1] == 1:
buff[i+1][j] = 1
elif buff[i][j+1] == 1:
buff[i+1][j] = 1

def rule2():
for i in range(len(buff)-1):
for j in range(len(buff[0])-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[i][j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff[0])-1:
buff[i+1][j] = 1
elif buff[i][j-1] == 1 and buff[i][j+1] != 1:
buff[i+1][j] = 1
elif buff[i][j+1] == 1 and buff[i][j-1] != 1:
buff[i+1][j] = 1
elif buff[i][len(buff[0])-1] == 1 or buff[i][0] == 1:
break
rule2()
nim = Image.new("1", (50,50))
nim.putdata(buff)
nim.resize((400,600)).save("output.png")

for a in buff:
for x in a:
if x == 1:
print "X",
elif x == 0: print " ",
print ""

for a in buff:
print a

May 14 '06 #7
Actually never mind either. I guessed I needed to append all values
after eachother in one row list:
x = []
for y in buff:
for z in y:
x.append(z)

thanks for the help

May 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rune Johansen | last post by:
Hi. I'm doing some image manipulation in an applet using the example code on this page: http://www.akop.org/art/pixels3.htm However, I really want an application rather than an applet, I just...
0
by: XMLGuy | last post by:
I initially posted this question in comp.theory but did not get much response. Please help! I think tree automata is very well studied area in math and computer science. Tree automata is also used...
9
by: Job | last post by:
Hi, I would like to find out what ASP/ASP.net can do with image manipulation. Does ASP have built in functions (eg. after upload to server) to manipulate images, like rotate, scale, crop etc.?...
9
by: zacariaz | last post by:
I dont know, and i dont much like javascript, however, i am told that the only way to do want i want to do, is with javascript, so here goes. zoom and cut is the only features i need. 1. the...
10
by: Pulzar | last post by:
Hi there, I want to show a simple image on a web page, and allow the viewer to select and change one of the colours used in the image, and immediately preview the result. I'd like to keep the...
5
by: defcon8 | last post by:
I thought people would be interested in this little script I wrote to reproduce the 256 simple automata that is shown in the first chapters of "A New Kind of Science". You can see a few results...
3
by: jon | last post by:
Hello, I've had long standing code that runs in IE, that I'm testing with firefox unsuccessfully now. The problem seems to be that images that I dynamically create don't fire their onload event...
8
by: shotokan99 | last post by:
i have this situation. i have a query string: http://www.myquerystring.com?x=xxxxx what this url does is it will return or start downloading a .png file. what i wanted to do is trap this png...
6
by: HypeBeast McStreetwear | last post by:
Hi, I've been doin a project for my C++ class pertaining to Cellular Automata. I'm having a little trouble so before I start I'll give you guys all the details so what I know, you'll know. ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.