CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Evolving the Mona Lisa


Sam Kennedy

Aug 28, 2012, 11:47 AM

Post #1 of 4 (2053 views)
Evolving the Mona Lisa Can't Post

I'm working on a script which should evolve an approximation of the Mona Lisa, however it doesn't really work.

Here is my script:

Here's an overview of the functions:
generate_genes() - fills the arrays xchrom and ychrom with x and y coordinates, and the arrays r/g/b/achrom with rgba values

get_dimensions() - gets the width and height of the target image (ml.png)

initialise() - sets variables to correct starting values

draw_images() - creates 10 images using the values from the "genes"

score_images() - the score is the sum of the difference in the rgb values squared, lower scores are better

output_best() - called when a new best is found, prints the image to a png file

soft_mutate_x/y/r/g/b/a() - mutates the value by incrementing it by a random amount

Any suggestions for improvements to the script would be very much appreciated. Currently I'm running it on a picture of the Japanese flag, after 583 generations the resulting image looks nothing like the target image, and there hasn't been any further improvement for the last ~30 minutes.

Thank You :)

(This post was edited by Sam Kennedy on Aug 28, 2012, 11:50 AM)

Veteran / Moderator

Aug 28, 2012, 12:00 PM

Post #2 of 4 (2048 views)
Re: [Sam Kennedy] Evolving the Mona Lisa [In reply to] Can't Post


add the following pragmas:

use strict; 
use warnings;

It may very well help you find problems in your code.

One question: you have this while(1) loop near the beginning, what instruction do you have to exit this loop? It may be somewhere deep in the code, I haven't seen it (I only had a very quick look).

Sam Kennedy

Aug 28, 2012, 12:03 PM

Post #3 of 4 (2047 views)
Re: [Laurent_R] Evolving the Mona Lisa [In reply to] Can't Post

It will never exit, it will keep running until killed. The longer it runs the more accurate the final image, so it's up to how patient to user is how long it runs for.

I'll use strict/warnings now and let perl shout at me haha

Sam Kennedy

Aug 28, 2012, 1:52 PM

Post #4 of 4 (2043 views)
Re: [Sam Kennedy] Evolving the Mona Lisa [In reply to] Can't Post

I managed to get this working, turns out crossover is very important in genetic algorithms and must be included.

If anyone is interested in the full script give me a shout and I'll upload it.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives