NST0: Transfering color palettes from one image to another

When I was studing StyleGAN, and the idea of style transfer from Xun Huang, I realized that the three color channels themselves - red, green, and blue - were themselves "styles". But the AdaIN operation assumed that the valid range was a real number, namely, between -inf and +inf... whereas pixels are bounded between 0 and 255. A naive AdaIN operation would result in clipping.

In ML, we deal primarily with real numbers and transform them to other ranges all the time. The best known is the sigmoid activation, which converts [-inf, +inf] to [0, 1]. another common operation is exponenent, which converts [-inf, +inf] to [0, +inf]. Sigmoid and expontent are simple functions with inverses. The inverse of the sigmoid function is called the logit function. By applying this to pixels, with some appropriate scaling, we can convert the range [0, 255] to [-inf, +inf] and perform AdaIN!

I had hoped that the logit function on a uniform distribution would result in a normal distribution, but that's one step more elegant than possible - the logit function applied for a uniform distribution is the logistic distribution, which looks like a normal distribution visually, but has higher skew. Oh well.

This was also an experiment with ONNX.js, which is a Javascript library for running ML models in the browser. When you "upload" an image, it only goes to the browser, never to a server. This way, I don't have to pay for hosting you get lower latency.

Note: This demo is designed for desktop browsers.

v2.4

Drag and Drop Content Image Here
Drag and Drop Style Image Here