Computer generated contemporary art (update)

(0 comments)

This is an update to the post from February 2016 with an improved algorithm (given below) for generating pleasing random images by sequentially shifting the colour of pixels across a canvas.

By using scipy.ndimage.convolve1d, one explicit Python loop can be dispensed with, speeding it up. Choosing to adjust the "seed" colours on the left hand column of pixels in the image, broad, colourful horizontal stripes can be introduced into the pictures.

Example computer-generated art image 1

Example computer-generated art image 2

import sys
import numpy as np
from scipy.ndimage import convolve1d
from PIL import Image

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

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

arr[1:,0] = [128, 128, 32]
arr[:height//2+100, 0] = [64, np.random.randint(64, 192), 128]
arr[1:,0] = arr[:-1,0] + np.random.randint(-rshift, rshift+1, size=(height-1, 3))


for x in range(1, width):
    arr[1:-1,x] = (convolve1d(arr[:,x-1], np.ones(3), axis=0,
                              mode='constant')[1:-1]/3 +
                   np.random.randint(-rshift, rshift+1, size=(height-2, 3)))
arr = arr.clip(0, 255)

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

Comments

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

There are currently no comments

New Comment

required

required (not published)

optional

required