Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Visual Experiments

Image reconstruction experiments using a small header-only multilayer perceptron (MLP).

The project provides two programs:

  • src/live.cpp — live reconstruction viewer using Raylib.
  • src/file.cpp — offline training that saves reconstruction outputs as PNG files.

Shared model, activation, image, and training logic lives in include/.


Quick Start

1. Build the Live Viewer

mkdir bin
g++ src/live.cpp -std=c++17 -O3 -march=native -o bin/live.exe -lraylib

2. Choose a Reconstruction Mode

Wallpaper-Style Reconstruction

For abstract or wallpaper-style results, do not use Fourier encoding or coordinate shuffling:

.\bin\live.exe --image .\images\<image-name>.png --params parameters\wallpaper.txt --rate 0.01

Exact Reconstruction

For a closer reconstruction of the original image, use Fourier encoding and shuffle the coordinates:

.\bin\live.exe --image .\images\<image-name>.png --params parameters\exact.txt --fourier 6 --shuffle --rate 0.01

Replace <image-name> with the name of an image stored in images/.


Project Structure

Visual-Experiments/
├── images/          # Input images
├── include/         # Shared model, activation, and image helpers
├── parameters/      # Network configuration files
├── src/
│   ├── file.cpp     # Offline reconstruction
│   └── live.cpp     # Live Raylib viewer
└── bin/             # Compiled executables

Requirements

  • C++17-compatible compiler
  • Raylib
  • stb_image.h
  • stb_image_write.h

Raylib Setup

Windows with MSYS2 UCRT64

Install GCC and Raylib:

pacman -S --needed mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-raylib

The live viewer links against Raylib using:

-lraylib

If your installation requires different linker flags, adjust the build command for your toolchain.


stb Image Setup

The project uses:

  • stb_image.h for loading images.
  • stb_image_write.h for writing PNG files.

The source expects the headers to be available as:

#include <stb/stb_image.h>
#include <stb/stb_image_write.h>

A typical directory layout is:

third_party/
└── stb/
    ├── stb_image.h
    └── stb_image_write.h

If stb is stored locally under third_party/, add it to the compiler include path:

-Ithird_party

For example:

g++ src/live.cpp -std=c++17 -O3 -march=native -Ithird_party -o bin/live.exe -lraylib

Build

Create the output directory:

mkdir bin

Live Viewer

g++ src/live.cpp -std=c++17 -O3 -march=native -o bin/live.exe -lraylib

Offline Reconstruction

g++ src/file.cpp -std=c++17 -O3 -march=native -o bin/app.exe -lraylib

Add any required include or linker flags depending on where Raylib and stb are installed.


Reconstruction Modes

Wallpaper-Style Reconstruction

Wallpaper mode is intended for more abstract, stylized, or smooth reconstructions.

Recommended configuration:

  • Use parameters/wallpaper.txt.
  • Do not use --fourier.
  • Do not use --shuffle.
  • A lower learning rate, such as 0.01, can produce more colorful results.

Live Viewer

.\bin\live.exe --image .\images\<image-name>.png --params parameters\wallpaper.txt --rate 0.01

Offline Reconstruction

.\bin\app.exe --image .\images\<image-name>.png --outdir output --epochs 20 --params parameters\wallpaper.txt --rate 0.01

Exact Reconstruction

Exact reconstruction is intended to reproduce the source image more closely.

Recommended configuration:

  • Use parameters/exact.txt.
  • Use --fourier 6.
  • Use --shuffle.

Live Viewer

.\bin\live.exe --image .\images\<image-name>.png --params parameters\exact.txt --fourier 6 --shuffle --rate 0.01

Offline Reconstruction

.\bin\app.exe --image .\images\<image-name>.png --outdir output --epochs 20 --params parameters\exact.txt --fourier 6 --shuffle --rate 0.01

Command-Line Options

Flag Description
--image Path to the input image
--outdir Output directory for generated PNG files
--epochs Number of training epochs
--fourier Number of Fourier bands used for positional encoding
--shuffle Shuffle samples before training
--rate Learning rate
--params Path to a network configuration file

Some options are specific to one executable. For example, --outdir is used by the offline reconstruction program.


Parameter Files

Files in parameters/ define the network architecture and activation functions.

Hidden layers use the format:

<width> <activation>

The final line defines the output activation.

Example

64 sin
32 sin
16 sin
8 sin
sigmoid

Experimental Notes

Some patterns observed during reconstruction experiments:

  • Wallpaper-style results: avoid Fourier encoding and coordinate shuffling.
  • Exact reconstruction: use coordinate shuffling with around 6 Fourier bands.
  • Lower learning rates tended to produce more colorful outputs.
  • Funnel-shaped networks often worked better than constant-width networks.
  • sin performed well for some wallpaper-style reconstructions.
  • A sigmoid output activation keeps output values in the [0, 1] range.
  • Increasing the number of Fourier bands beyond 6 often produced worse results.

These are experimental observations rather than fixed rules. Results vary depending on the input image, network architecture, and training configuration.

Ai Usage

  • Some of the code in mlp.hpp was optimised by using ChatGPT to vectorise matrices resulting in better performance

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages