Computer generated contemporary art

(3 comments)

Just a quick selection of images randomly-generated by the following 10 lines or so of Python.

import sys
import numpy as np
from PIL import Image

try:
    filename = sys.argv[1]
except IndexError:
    filename = 'img.png'

rshift = 3
width, height = 600, 450
arr = np.ones((height, width, 3)) * 128

for y in range(1,height):
    arr[y,0] = arr[y-1,0] + np.random.randint(-rshift, rshift+1, size=3)

for x in range(1, width):
    for y in range(1,height-1):
        arr[y,x] = ((arr[y-1, x-1] + arr[y,x-1] + arr[y+1,x-1])/3 +
                            np.random.randint(-rshift, rshift+1, size=3))

im = Image.fromarray(arr.astype(np.uint8)).convert('RGBA')
im.save(filename)

Computer-generated art image 1

Computer-generated art image 2

Computer-generated art image 3

Computer-generated art image 4

Computer-generated art image 5

Computer-generated art image 6

Current rating: 4.5

Comments

Comments are pre-moderated. Please be patient and your comment will appear soon.

Joseph C. Slater 7 years, 7 months ago

Dr. Hill,
I'm working through your book, playing with examples, and this one drew my attention. However, I cannot figure out where the Image module is (with a capital "I"). There is an image package on pypi, but it's clearly not the same. Would you please clarify where this module can be found?

As an aside: my compliments on the text. I used to think I knew Python. I have two packages on pypi. I now realize that I have much more to learn. Thank you for such a wonderful text.

Link | Reply
Currently unrated

christian 7 years, 7 months ago

Hi Joseph,
Thanks for your kind comments: I'm constantly finding new things to learn about Python.
To answer your question, the most popular recent imaging library for Python is Pillow (https://python-pillow.org/) a fork of the older PIL library, and this contains the Image module.
I've updated the code above to do the import properly with this library: you can install it with pip or conda if you don't have it already.
Cheers,
Christian

Link | Reply
Current rating: 5

Peter 5 years, 7 months ago

Hi Christian

Thank you for this post ! Really great this "simple" generator - a loneley example that deserves the name ART generator ! It has motivated me to eliminate the two outer for-loops. This resulted in a speed gain of factor 12 (code: https://alpynepyano.github.io/healthyNumerics/posts/accelerated-pastel-art-with-python.html)

And the mystery curves are inspiring too (https://alpynepyano.github.io/healthyNumerics/posts/decorative-mathematical-functions.html)

Thank you, Peter

Link | Reply
Currently unrated

New Comment

required

required (not published)

optional

required