evoart: howto/art

evoart: howto/art

The EvoArt program mimics the evolutionary processes of selection, reproduction and mutation to generate successive populations of images. Upon starting EvoArt, you are presented with a population of fifteen images, from which you can choose two as parents. The parents are merged and mutated to produce a new population of images, from which you can choose two as parents ... and so the search continues until you find an image you like.

The method of generating populations if objects (images) is known as genetic programming. This page offers a brief explanation of how these processes are applied to EvoArt – how images are represented as programs so they can undergo genetic programming, how genetic programming works and how the programs are turned into images. A default population of images is provided as a basis for generating more complex artworks. My own artworks will be added to as I create them.

how evoart generates images

Representation: Genetic programming is an optimization process that mimics biological evolution to evolve populations of computer programs. In EvoArt, these programs are function trees representing simple equations that take coordinate values and random numbers as parameters. When applied to the x and y pixel-coordinates of an image structure, the output is a value describing the luminance of each pixel. (The image structure holds coordinate values in the range of -1 to 1. Image appearance will consequently remain the same for all but very small resolutions.) The tree below-center represents the equation cos(x) + (x * y) . When applied to each x and y pixel coordinate, it produces the luminance image to the left and the colour images to the right.

Function Set: The functions that constitute the nodes of the function tree were arrived at by experimentation. Functions that I felt were hindering the search process were removed. The default function set is, at present, incredibly simple, with only a few basic functions. It may be expanded at a later date, giving the user control over what can be added to the default set. Each function takes only one or two arguments, which can be other functions or terminals (x and y coordinate values and random numbers between zero and one).

    One Arg. Functions : abs, cos, sin
    Two Arg. Functions : add, sub, mul, div
    Function Terminals : coord x, coord y, random

Genetic Programming: Upon starting EvoArt, the user is presented with a population of images from which two can be selected as parents for mating. It is usual for a fitness function to rank the fittest members of the population, those with a high rank are thus more likely to reproduce. For evolutionary art programs, it is the user who supplies the fitness function by selecting parent images for mating.

The function trees representing these parent images now undergo crossover and mutation operations to produce a new population of images. Crossover swaps randomly selected subtrees from each parent tree to generate new offspring. Each offspring has a pre-determined probability of mutation, which can operate on randomly selected nodes and subtrees. If mutation operates on nodes and the selected node is a function type (cos, div, add, et cetera), it will be replaced with one that takes the same number of arguments, if it is a terminal (x, y, or rand) then it will be replaced by another terminal. If mutation operates on subtrees, then the selected subtree will be replaced by a randomly generated subtree of a similar size.

The process of selecting parents, crossover and mutation, adds considerably to the size of the function trees. Final images are generally represented by trees containing many hundreds, if not thousands, of nodes. Consequently, the time taken to produce good images can increase dramatically as the search continues.

Algorithm Pseudocode: The algorithm is very straightforward, once a default population of images has been generated, the user selects parent images for mating. The parent images undergo crossover and mutation to produce a new population. The process finishes when the user has found a satifactory image.

    Load Images: a default population OR a randomly generated population
    Repeat: 
        Evaluate fitness by selecting parent images for mating [Selection]
        Apply crossover operation to the parent function trees [Crossover]
        Mutate offspring only if mutation probability satisfied [Mutation]
    Until: An aesthetically pleasing image has been found

Elitism is Good: It is common to practice elitism when generating a new population. The parent images represent the best thus far and there is no guarantee that the offspring will be as good. Consequently, images chosen as parents pass into the next generation unaltered.

Generating Colour: One approach for generating RGB colour is to phase shift the luminance values at each pixel. In other words, the colour array is interpreted by three sine waves that have been shifted out of phase by 90, 180 and 270 degrees respectively. All of the colour channels change intensity gradually, and at the same time. The problem with phase shifting is that none of channels intersect, so there are no greys.

This is corrected by frequency shifting the luminance values to generate the required intersections, so that colour images have the full complement of greys. Locking each channel has the effect of producing greyscale images. The diagram below illustrates the effect on colour frequency when shifting luminance by pi/2, where v is the luminance value and f is the value of the frequency shift.


Red = sin( vf (pi/2) )       Green = sin( vf (pi) )       Blue = sin( vf (3pi/2) )

It is mathematiclly very simple to obtain the values for each of the colour channels. Calculate the luminance (v) and frequency shift (f) at each pixel and multiply that value by pi/2 for Red, pi for Green and 3pi/2 for Blue, then calculate the sine for each of those values.

default images

Creating images from a randomly generated population can be very time-comsuning, so the user is given a head-start with a default population of fifteen images. The images can be viewed in greyscale and populations of randomly generated images can be created should the search start to falter. EvoArt also stores the previous 20 parents sets, any of which can be introduced during a search. The images below are of the default population and their greyscale counterparts. Users can generate, store and load their own images and create their own populations.

using evoart

Matlab Version: Evoart was developed and tested using Matlab 6.5 (R13). It has not been tested in other versions of Matlab.

Starting EvoArt: You must first set the Matlab default directory to the EvoArt directory. You can then start EvoArt by typing 'evoart' at the prompt in the Matlab command window. It can take 10 or 15 seconds to start-up as it must first load the default function trees from file and translate them into images. Once started, you are presented with a population of fifteen images from which two can be chosen for mating. Two images already fill the parent slots in the bottom right corner.

Hovering the mouse over any of the controls in the application window will produce a tooltip describing that control. Notice that buttons and sliders are grouped together in panels. Here's a brief description of each control group.

B&W Button: Converts the current population of images to greyscale by locking all the color channels, so forcing intersections. Pressing the button again will convert them back to colour. See the default population of images above for examples.

Invert Button: Inverts the current population by phase shifting the colour channels by 180 degrees, producing a pseudo–negative image. Pressing the button again will restore them. The following screenshots illustrate the effect of inversion on the first row of the default population for both B&W and colour images.

Colour Frequency Slider: This sits next to the Invert button. The slider has a range between 0% and 100%. Increasing the frequency increases the degree of shift. Frequency shift is consistant across all colour channels.

Set Button: Applies the desired frequency shift to the current population. The screenshots below illustrate a 50% frequency shift on the first row of the default population for both B&W and colour images. Notice that more complex images (far left and far right) now appear squashed. This effect increases as more shift is applied.

Load and Save Buttons: Pressing the Save button displays a Save dialogue box open in the zoo directory. (The zoo directory is created automatically if one does not already exist.) Pressing the Load button displays an Open dialogue box, which opens in the zoo directory if one exists, otherwise it opens in the default directory.

Parent Set Dropdown Menu: You may choose to mate a parent from a few generations ago with one of the images in the current population. EvoArt remembers up to twenty changes of parent images. They are stored in succession and can be accessed from the Parent Set drop-down box. It is a simple process of choosing a previous Parent Set and mating it with a choice from the current population.

Rand Button: Pressing this will replace the current population with a randomly generated set of images. This is useful if you need to re-start the search with a new parent image. The current default population started life as a random set of images. It took me several days and many hundreds of populations to get fifteen good images.

Mutation Rate Slider: Before mating the parent images, you can decide on mutation rate and type of mutation. The mutation rate sets the probability of a sibling undergoing mutation. (A sibling is an image represented by a function tree that has been generated from the parent image function trees.) If a low rate (under 10%) is set then there is a good chance that mutation will not take place OR that the mutation functions will choose nodes or terminals lower down the tree to mutate. Mutation will not be applied unless the slider is moved above 0%. You choose the mutation type with the adjacent dropdown menu.

Mutation Type Dropdown Menu: There are three types of mutation to choose from. Mutate Random Subtrees replaces a randomly chosen subtree with a randomly generated subtree. Mutate Random Nodes replaces a randomly chosen node with a randomly generated node of appropriate type, i.e. cosine is replaced with sine or absolute, add is replaced with divide, subtract or multiply. If Mutate Subtrees and Nodes is chosen then there will be a 50% chance that either of the above will be applied. Remember that a sibling will only undergo mutation if it meets the probability set by the Mutation Rate Slider.

Mate Button: Pressing this generates a new population of images from the chosen parents. Mutations will be applied to any sibling that meets the probability you have set. Any color settings remain consistant across generations.

saving images

Parent images can be opened for viewing and saved in various formats, such as jpg, tiff or bmp. You simply click on the parent image you wish to save and it will appear in a new window. You can then export the image in the required format. As you can see from the screenshot below, the viewed image is much larger than the original. If you decide to save then it will be larger still. I would recommend you save image files using a lossless type such as tiff.

artworks

This following set of images represent a more intense effort than the default population images. They took many hours and many more generations. More will be added as I create them...


sixteen
          
seventeen