Generative Art – The Interim Steps

Re: my previous post, there were some questions about the eigenvectors I had created, and what had happened with them when I tried to reconstruct the images.

I’ll attempt to illustrate that here.

Note that I may not show ALL of the code. Some of the functions I called are part of the assignments for the Coursera Machine Learning course (and are actually this week’s assignments), and we’ve been asked not to make those solutions public. If you really want to see the implementations, pinky-swear that you’re not taking the course, and I’ll email them to you.

So back to the beginning. Once again, here are our original images:

Girl before a Mirror0 through 9


So let’s look at the first part of the code. The very first part is just like in the previous post:

We clear our existing data and read in the images.

But this time, we’re going to reshape the N-dimensional vectors into 2-dimensional matrices so we can run our Principal Component Analysis:

All of the code up until this point will be reused in our experiments. We read in the images, translate the vectors to a 2-D matrix, and run PCA. Now comes the fun part: we need to project the images into the eigen space.

It doesn’t make any noticeable difference which eigenvectors we use here, though they are different. They just may be so similar as to not matter:

Finally, we recover images by reversing our projection and writing the results to disk. It’s here that I tried recovering each image using the other’s eigenvectors, to no noticeable change:

But as you can see, there’s no discernable difference:

picasso_origpicasso_swap

johns_origjohns_swap

Now we can do some interesting things by reducing the number of components we use to project and rebuild the images (the K value above). There’s still no difference when we go to reconstruct, so I’ll just show each image once from now on.

What if we reduce K from 3 (the size of the eigenvector matrix) to 2? We get kind of a neat muted palette:

Girl before a Mirror - K = 20 through 9 - K = 2

And when K = 1, we get a pretty good grayscale.

Girl before a Mirror - K = 10 through 9 - K = 1

We can also do some interesting color shifting by transposing our eigenvector matrices at certain times.

If we transpose when we project the data (when K = 3), we get a huge green shift:

Girl before a Mirror - Transpose on Projection0 through 9 - Transpose on Projection

Alternately, if we transpose the matrix when we go to recover, we get a big red shift:

Girl before a Mirror - Transpose on Recovery0 through 9 - Transpose on Recovery

Again, nothing we couldn’t have done in a few seconds in Photoshop, but pretty fun to play with, at least.