Classical Style Transfer Without Neural Networks
Patch-based Texture Synthesis
University College Dublin
Description
Overview
This project presents a non-parametric style transfer algorithm that blends a content image and a style image using patch-level pixel matching rather than deep neural network representations.
Technical Concept
Unlike traditional neural style transfer (such as Gatys et al.) which uses intermediate activation maps of deep networks to separate and recombine content and style, this algorithm handles the transfer directly on the pixel space:
- Content Representation: The spatial structures, edges, and objects layout are captured by the relative spatial positions of the patches in the content image.
- Style Representation: The visual style—which consists of tone, contrast, sharpness, and local texture statistics—is captured by local statistical features (mean and standard deviation) of the style image.
Algorithm Intuition
By replacing each small local patch in the content image with a visually similar patch retrieved from the style image, we transfer the texture and styling of the style image while preserving the overall shapes and spatial boundaries of the content image. This approach is heavily inspired by classical non-parametric texture synthesis (Efros & Leung) and statistical texture models (Portilla & Simoncelli).
Parallel Execution & Performance
Patch-matching algorithms can be computationally intensive when executed sequentially. This implementation is written in Python and supports multi-core parallel computing to speed up execution.
Usage
You can run the script specifying padding, stride, and whether to run in single-core or multi-core mode:
python main.py p 3 2
- Parameter 1 (
porm): Mode of operation. Specifypto allocate all available CPU cores in parallel, ormto run on a single core. - Parameter 2 (
3): Padding size around patches. - Parameter 3 (
2): Stride value for patch matching.