Skip to content

seece/SingleImageNCAFiltering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Single Image Filtering with Neural Cellular Automata

An experiment with learned image filters for small GLSL shaders. Based on the μNCA model.

Input-output diagram.

This repository is split into two parts:

  • renderer, a Windows C++ OpenGL renderer, and
  • training, a Jupyter notebook for training the filters with PyTorch.

Unfortunately the first runs only on Windows and the second one on Linux. I've used Windows 10 with WSL myself to run everything.

How it works

Based on Alexander Mordvintsev and Eyvind Niklasson's research on neural cellular automata (NCA) published in these three papers:

Both the model and the training objective have been modified for this experiment. The model is now running two smaller CAs in a row and starts from a "feature" image instead of pure noise. See the included notebook for more details.

I used four channel images to make it easier to implement on the C++ side. With more channels more elaborate textures can be generated, as shown in papers linked above.

The loss function is a combination of a "content" and "style" losses just like in style transfer tasks. Increasing the content loss weight makes results sharper but with less contrast:

Content weight factor comparison.

Download a short video demonstration of the final filter: processing.mp4.

Is this better than the alternatives?

It may be possible to get similar results with a small convolutional neural network or a hand-tweaked bilateral filter.

Creating your own filter

It's pretty arduous but all the pieces are there:

  1. Export a raw .data image and a matching PNG with renderer
  2. Crop the PNG to your liking and encode its x and y in the filename like img_crop_x_y.png.
  3. Stylize your PNG in whatever way you wish.
  4. Put the two files in training/images and add their paths to the notebook script.
  5. Run the notebook and wait until it prints the GLSL code at the end.
  6. Copy the GLSL snippets to draw.frag and present.frag in the renderer/blossom directory.
  7. Compile & run the renderer project

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published