RainbowRedux / TextureUpscalingPipeline

A framework to perform multiple processing passes on textures in order to upscale them.
MIT License
5 stars 1 forks source link
esrgan modding pillow textures upscale

Texture Upscaling Pipeline

CodeFactor

A framework to perform multiple processing passes on textures in order to upscale them. This makes it easy to add new passes or iterate development on pre- and post-processing stages.

Requirements

Setup

  1. Clone the repo
  2. Setup submodules
    git clone --recurse-submodules https://github.com/boristsr/TextureUpscalingPipeline.git
  3. Install the requirements from requirements.txt
  4. Install CUDA
  5. Install PyTorch and torchvision from the website
  6. Place desired ESRGAN models from the authors page into the directory
    TextureUpscaler/ESRGAN/models
  7. Configure settings.json

Usage

All images need to be in a format that pillow can read. Preferably this is PNG so it can be lossless.

Configure settings.json with the search path and extensions to search for.

{
  "searchPath": "D:/gamedata",
  "extensions": [".CACHE.PNG"]
}

Run the program

python UpscaleTextures.py

When the process has finished successfully all images will be saved alongside the originals with .HIRES.extension

Customization

The purpose of this program is to tie together many processing stages that can be performed before and after the upscaling step. The implementation of each stage is defined in a few modules under TextureUpscaler directory, and the order of steps is defined in UpscaleTextures.py

Adding a new processing step

The simplest way to add a new step is to add a custom function which works on a single image and can be passed to

run_processing_stage(invert_texture, images, settings)

Any function passed to run_processing_stage should take 4 parameters:

When a function completes successfully it should return True so that run_processing_stage updates the paths correctly in the pipeline.

invert_texture is a simple example used for testing the pipeline and makes a good learning example. Below you can see it.

from PIL import Image
import PIL.ImageOps

def invert_texture(inpath, outpath, workingImage, settings):
    """Inverts the colors on the texture specified"""
    print("Inverting texture: " + inpath)
    image = Image.open(inpath)
    inverted_image = None
    try:
        inverted_image = PIL.ImageOps.invert(image)
    except IOError:
        return False
    inverted_image.save(outpath)
    return True