473,809 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2874
de*****@gmail.c om 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.goo glegroups.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(bim g)
nim.resize((400 ,200)).save("ou tput.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(buf f)
nim.resize((400 ,600)).save("ou tput.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(buf f)
nim.resize((400 ,600)).save("ou tput.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
5445
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 can't figure out how to do the image loading and manipulation when it's not from inside an applet. Any hints on the subject are appreciated.
0
1812
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 often in context of XML and will appreciate your response and opinions about using tree automata for XML. I am looking for an algorithm that performs intersection operation on two tree automatas. I unable to find any in textbooks or online....
9
2152
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.? Or are 3rd party solutions needed to do this? I am a php/codfusion programmer and know nothing about asp, so I'm hoping somebody here can help me out.
9
3379
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 image that need manipulating is places on the server. dont need js for that ;-) 2. the client has the oppotunity to manipulate the image. cut and zoom. 3. the image i saved on the server.
10
3493
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 image processing away from the server to make the colour selection/preview process quicker, and I also don't want to pre-generate all possible images as there are too many colours that can be selected. Does JS (or any JS libraries) provide image...
5
2137
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 without running the script, at http://cooper-j.blogspot.com . And here is the code (You will need PIL (Python Imaging Library)): <code> import Image # Contract: # To simulate simple cellular automata.
3
26760
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 in firefox. The onload method I assign is never being called. Any ideas why firefox isn't calling this, or what I can do for a workaround? Below is approxiatemate code of what I'm doing...
8
2015
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 file and manipuate the image like resizing, color...etc. how can i do this?
6
3455
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. In a nutshell I know I have to start with an array in "Generation 0" and the code essentially will create a copy but I don't know how to start. Can you guys help me? I mostly just need a template to create the 2D array and a template to pass in a...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.