Matt Fowles's AI Lab 1


The basic idea for this lab was to use the genetic algorithm provided us, to solve a problem. I tried to breed an edge finding matrix. The general idea is that one can convolve a matrix with an image to achieve various effects. One of these is edge detection.


Representation

I chose to represent my transformation as a 5x5 matrix of values in the range [-7,7]. Each number could then be represented by 4 bits in my chromosome. For example
0 0 -7 0 0
0 1 1 1 0
-5 1 4 1 -5
0 1 1 1 0
0 0 -7 0 0
->
0000 0000 1111 0000 0000
0000 0001 0001 0001 0000
1101 0001 0100 0001 1101
0000 0001 0001 0001 0000
0000 0000 1111 0000 0000
Really, the representation was fairly simple. It was long, but simple. I was hoping that this would allow the GA enough space to come up with interesting answers.


Fitness functions

For my fitness functions, I applied the matrix for each individual to a sample image. I then did a square sum difference on the result and my target image. I had two normalize the results of the SSD, to keep everything in a reasonable range. I then divided by the total number of pixels to get a per pixel error. Since an SSD will return smaller values for a better match, I then took the reciprocal to be the actual match value.

I tried doing this with a couple of different edge map function; however, none of my results were inspiring or useful.


Parameters

I ran the GA with a population size of 50, a chromosome length of 100, and a generation limit of 200. Sufficed to say that it takes a long time to run.


Results

There are two distinct categories of results. Those produced with xv's edge map and those produced with XnView's edge map. While neither set of results is particularly good, the two edge maps do look substantially different. You will probably notice that the result images are slightly smaller than the start image. Rather than try and deal with the cases where the matrix is not fully on the image, I decided to ignore them. This resulted in a loss of 2 pixels from each side.
Start Image
xvstart.png
Target Image
xvtarget.png
Results of XV edge matching
Found in generation 126 xv1.png Found in generation 179 xv2.png Found in generation 44 xv3.png Found in generation 197 xv4.png Found in generation 171 xv5.png
Found in generation 68 xv6.png Found in generation 194 xv7.png Found in generation 174 xv8.png Found in generation 199 xv9.png
Start Image
xnstart.png
Target Image
xntarget.png
Results of XnView edge matching
Found in generation 175 xn1.png Found in generation 16 xn2.png Found in generation 79 xn3.png Found in generation 184 xn4.png Found in generation 114 xn5.png
Found in generation 13 xn6.png Found in generation 178 xn7.png Found in generation 197 xn8.png Found in generation 191 xn9.png



Analysis

My first attempt at this project used the entire image for the data GA, rather than just the small section you see above. The problem with this is that much of the image is not edge, and as such not enough focus was placed on the actual edge detection, and more emphasis was placed on getting the background to be the correct color.

After focusing the image slightly, I still have been unable to achieve good results. I think that this is because successful edge maps depend on most of the matrix. I was hoping that each cell in the matrix would be able to act independantly allowing the problem to have clean building blocks; however, I am no longer convinced that this is the case. It seems likely that the entire filter has to be somewhat carefully designed to achieve any specific effects. Except for a general blur, which seems to happen quite freely.

It looks like (despite my efforts to the contrary) the GA is still focusing in on the background and mapping to that rather than the edges, which are the true area's of focus. This phenomenon probably stems from the fact that general intensity control is easier to mix and match then edge detection. I do not think that a GA would necessarily fail to learn develop an edge detection; however, an extreme amount of care would have to be taken to select the training set.

Worth note, is that the XnView data set did not blur the image so much as reduce the contrast, whereas the XV set heavily blurred the image. All in all, I would say the the GA was not successful. While I do not think that it would be impossible to make a GA which produces an edge detection system. I think that a drastically different approach then the one I have chosen would be necessary.

I did a little bit of work trying to seed the initial population with good matrices, unfortunately these were quickly destroyed via crossover, and never really show up in later generations. The resultant best fit was always one of the seeded matrices.

Last modified 2003-10-07 22:15 EST