Artistic Style Transfer With C# And A Neural Network

Mark Farragher
9 min readDec 12, 2019

Style transfer is a process where we recompose an image in the style of another image by transferring the artistic style from one picture to another using a convolutional neural network.

It looks like this:

Visiting Picasso with dynamic style transfer

This is a photo of Pablo Picasso painting a bull on a sheet of glass, but the image has been repainted by a neural network using the artistic style of another painting.

You can watch the full video here: https://www.youtube.com/watch?v=FzvTLEB_3KY

Pretty cool, right?

This is a short fragment from Visite à Picasso, a 1950 film by Belgian filmmaker Paul Haesaerts, in which Picasso demonstrates his skills.

Every frame of the video has been processed by an Artistic Style Transfer neural network. The result is a hypnotic and dreamlike sequence where we see Picasso painting his bull, but the visual style keeps changing as the software switches seamlessly between different artistic styles.

So at its core, style transfer is a process that takes an image which we call the Content Image, and combines it with the artistic style of a second image called the Style Image. This produces the Mixed Image:

The artistic style of the middle image gets applied to the content image

You can see that the original landscape is still visible in the mixed image, but the colors, textures, and visual style are all taken from the style image.

To perform artistic style transfer, the first thing we’re going to need is a fully trained image classifier. A popular choice is the VGG19 convolutional neural network. We can download this network from the Internet and load it in an app.

So here’s how the style transfer process works.

We start by showing the content image to the neural network and measuring the feature activation in the deepest convolution layer of the neural network. We’ll treat this level of activation as a baseline. When we show other images to the network, we’ll get a different feature activation in the deepest layer. The difference between the baseline and the actual activation level is called the…