Every RGB Image Evolver

This project was inspired by and by my previous work with genetic algorithms.

There are 16,777,216 8 bit RGB colours. If you made an image that contained each colour exactly once it would be a 4096 by 4096 pixel square. This program takes an image of your choice and then tries to generate an image that uses only one of each colour that matches it. This is a huge feat as the image size is so large, finding the best match for the entire image would require millions of operations performed upon millions of pixels. Rather than taking a long time to find an exact answer, this program uses a genetic algorithm to work towards an acceptable solution in a much shorter period of time.

The general flow of the program is:

  1. User loads an image.
  2. The image is stretched to be exactly 4095x4095 pixels.
  3. An image that contains one of every colour is created.
  4. Two pixels in the allRGB image are chosen at random.
  5. Work out how closely they match the reference image.
  6. Work out how closely they would match the reference image if they were swapped around.
  7. If the swap incurs an improvement, swap them.
  8. Repeat steps 4-7 until the user is happy with the result.

Each time the program gets from step 4 to step 7 counts as a generation, each time the pixels are swapped counts as an improvement.

The simplicity of the algorithm means that many thousands of checks and swaps can be made every second. This, combined with the random coverage of the image, quickly leads to the visible improvement of the solution.

Try it yourself: allRGB.jar

Source code (MIT License): Github

View Image View Image View Image View Image
  • Resize the window until only the generation and number of improvements are visible to speed up the program.
  • The images shown in the program often seem much worse quality than they are in reality, save the image and view in another program for a better look.


If you are having trouble running the program, please try this quick guide.

What Am I Looking At?

When you run the program you should see two images. The image on the left is the 'reference image' this is the image which the algorithm attempts to copy using exactly 1 of each colour. The image on the right is the 'allRGB image' this is the image which the algorithm works on, it will keep on evolving the image in an attempt to make it match the reference image.

Neither of the images will be shown full size on your screen because they are huge, this means that Java scales them down to make them fit. This scaling reduces the quality of the image which means saving the image to your computer and opening it in a photo viewer is the only way to really see the result of the algorithm.

At the top of the screen are some numbers:

  • Gen: This is the number of 'generations' i.e. the number of times the genetic algorithm has been run.
  • Improvements: This is the number of generations in which the mutation has been positive. When a new image is first loaded, this number should be close to the number of generations however as time goes by and more improvements are made, it becomes harder to find a beneficial mutation and therefore the rate at which improvements are made will decrease.
  • FPS: This is the number of 'frames per second' which is the number of times the entire program runs each second.

The Interface

Unfortunately in this version the user interface is very basic.

Image on the left:

  • Left click: Load a reference image, the image will be scaled to 4096x4096 pixels.
  • Right click: Save the reference image.

Image on the Right:

  • Left click:
    • You are given the option to reset the allRGB image, this will wipe all progress.
    • If you decline the first option, you are asked if you'd like to load an image, combined with the save feature this allows you reload old allRGB images so you can continue to improve them.
  • Right click: Save the allRGB image.

Can't load images?

If you've followed the instructions above and have not been able to load your own image, it might be that Java's security settings are blocking the program from loading images. To get around this you can try running the program from the command line, or on WIndows:

  • Right click in an empty part of the folder (or desktop) that you're running the program from.
  • Go to New and create a new .txt file.
  • Inside the .txt file write: java -jar "Encrypt.jar". (Where "Encrypt.jar" is the name of the file you are trying to run).
  • Save the .txt and then rename it to "run.bat", when asked if you're sure you want to change the 'filename extension' select yes.
  • Now when you run the 'run.bat' file it will run the program with permission to save, edit and load images.

Devlopment Log

~ May 2014 ~

While not enough progress has been made to publish an interactive version, I've been working on a better interface and a few slightly modified versions of the algorithm.

The easiest modification is simply to look for the worst match for each pixel rather than the best, this results in a negative of the image being produced. I'm also working on an exact version of the algorithm that looks for the closest match for a pixel out of all the remaining colours, however due to the very large number of comparisons that need to be made, it is extremely slow.

View Image

Features of this version:

  • Choose from a selection of algorithms, which will yield different results from the same start point.

~ April 2014 ~

This first version of the program is very basic, the genetic algorithm is very optimised however it has been little more than a toy for me to play with and the user interface is rather basic.

View Image View Image View Image

Try it yourself: allRGB.jar

Features of this version:

  • Load your own image and save the resulting allRGB version.
  • Reload an old allRGB image to continue improving it.
  • Load your own colour set, in place of the allRGB image.
  • Displays the number of generations the algorithm has undergone and the number of generations which have resulted in an improvement.