ProGamerGov / Neural-Tools

Tools made for usage alongside artistic style transfer projects
184 stars 30 forks source link
coarse color color-transfer controlling factors fine grayscale-images linear-color-transfer luminance luminance-transfer neural neural-style neural-style-pt perceptual scale scale-control style style-transfer tools transfer

Neural-Tools

Tools made for usage alongside artistic style transfer projects based on the Controlling Perceptual Factors in Neural Style Transfer research paper by Leon A. Gatys, Alexander S. Ecker, Matthias Bethge, Aaron Hertzmann, and Eli Shechtman.

In-depth information about how to perform Scale Control and Color Control, including the Neural-Style parameters used in the examples, can be found on the wiki. The Color Control feature is broken down into two different features known as Luminance-Only Style Transfer, and Color Matching. The Scale Control feature focuses on separating style image content/shapes, and style image textures.

Linear Color Transfer

The match_color function's code comes from the very talented Leon Gatys' code here. This script was developed to help enable Scale Control in Neural-Style, but it can be used for anything else that requires linear color transfer. Supported image formats include: jpg, jpeg, png, tiff, etc...

Scale Control examples made with Neural-Style, can be viewed here.

Dependencies:

sudo pip install scikit-image

sudo pip install imageio

sudo pip install numpy

sudo pip install scipy

Usage:

Basic usage:

python linear-color-transfer.py --target_image target.png --source_image source.png

Advanced usage:

python linear-color-transfer.py --target_image target.png --source_image source.png --output_image output.png --mode pca --eps 1e-5

Parameters:

Examples:

Source Image:

Target Image:

Output Image:

See here for how to use this script for Scale Control.

Linear Color Transfer is also used for Color Matching Style Transfer:

See here on the wiki, for more details on Color Matching Style Transfer.



Luminance Transfer

This script was developed to help enable colour control in Neural-Style, also known as "Luminance Transfer". This script uses code from Leon Gatys' code here. Supported image formats include: jpg, jpeg, png, tiff, etc...

Luminance transfer/Color Control examples made with Neural-Style, can be found here.

How It Works:

Currently, all available models are trained on images with the RGB/BGR color space. An image's luminance can represented in the form of gray scale color space image, which can be converted to RGB format for Neural-Style. After the gray scale images are run through Neural-Style, re-applying the color to your output is done with the use of the LUV color space.

Basically due to pre-trained model limitations, gray scale images are used to transfer luminance, and a color space supporting luminance is used to transfer the colors back to the finished output.

Dependencies:

sudo pip install scikit-image

sudo pip install imageio

sudo pip install numpy

sudo pip install scipy

Usage:

Basic usage:

python lum-transfer.py --content_image content.png --style_image style.png

Advanced usage:

python lum-transfer.py --cp_mode lum --content_image content.png --style_image style.png --org_content content.png --output_style_image output_style.png --output_content_image output_content.png

Parameters:

The required input images and the output images, are dependent on the --cp_mode option that you choose:

Mode: lum

Mode: match

Mode: match_style

Mode: lum2

Examples:

The style image is adjusted to match the content image:

After Neural-Style:

Final ouput image: