Skip to content

fjebaker/brimage

Repository files navigation

BRImage

BRImage

Build Status PyPi Version Downloads per Week

Glitch Art Library and command line tool for generating glitch-art effects inspired by CRT monitors.

One-liner install:

pip install BRImage && brimage -h

Note: requires Python3.7 or higher.

Table of Contents

  1. Usage
    1. Frequency Modulation
    2. Random Walk
  2. Installation
    1. pypi
    2. Building from source
  3. Changelog

Usage

BRImage can be used as both a command line interface and python package. The command line tool provides basic access to each algorithm.

brimage -h

Frequency Modulation

Command line:

$ brimage freqmod -h
usage: BRImage freqmod [-h] [--omega OMEGA] [--phase PHASE] [--lowpass LOWPASS] [--pquantize PQUANTIZE] [-o OUTPUT_FILE] input_image

Frequency modulation algorithm for images. Implicitly converts to greyscale.

positional arguments:
  input_image           Input image path; most common formats are accepted.

optional arguments:
  -h, --help            show this help message and exit
  --omega OMEGA         Frequency omega; controls line spacing. Range: 0.0 to 1.0, >1.0 also works, but ugly. (default: 0.3)
  --phase PHASE         Controls the phase range that is used to map the pixel values into. Higher values distort the image more. Range: 0.0 to 1.0 (default: 0.5)
  --lowpass LOWPASS     Set the lowpass filter amount. Lower values blur out fine detail more. Set to 0 disables the filter. Preconfigured to 30Hz sample rate. Range: 0.0 to 1.0. (default: 0)
  --pquantize PQUANTIZE
                        Post-quantize number; integer number of colours to quantize image to after frequency modulation. Range: >=0. Value of 0 disables post-quantize (default: 0)
  -o OUTPUT_FILE, --output_file OUTPUT_FILE
                        Output image path. (default: output.jpg)

Example:

Input Image Output Image

Random Walk

Command line:

$ brimage randomwalk -h
usage: BRImage randomwalk [-h] [--lines LINES] [--greyscale] [-o OUTPUT_FILE] input_image

Random walk algorithm for images. Most values are still hardcoded in a header file, which requires recompilation. Later release will make this available through python.

positional arguments:
  input_image           Input image path; most common formats are accepted.

optional arguments:
  -h, --help            show this help message and exit
  --lines LINES         Number of individual line paths to draw. (default: 500)
  --greyscale           Process image as greyscale. (default: False)
  -o OUTPUT_FILE, --output_file OUTPUT_FILE
                        Output image path. (default: output.jpg)

Example:

Input Image Output Image

Installation

pypi

I've made the project available with pip (you can view the project here):

pip install BRImage

and run with

brimage

Building from source

First, clone the repository

git clone https://github.com/Dustpancake/BRImage && cd BRImage

Generate the SWIG files; for this we require numpy.i:

curl "https://raw.githubusercontent.com/numpy/numpy/master/tools/swig/numpy.i" > BRImage/clib/numpy.i

Then we generate the .py and .cxx files with

swig -c++ -python -py3 BRImage/clib/algorithms.i

The next stage can be done in a few different ways:

  • Isolated build directory

Build the project with the --target pip flag, to prevent it from being installed into the environment:

pip install --target build .

alternatively, use the develop mode

pip install -e .
  • Install dependencies and build inplace:

Install the required modules with

pip install -r requirements.txt

Then to only build the external C++ modules, use

python setup.py build_ext --inplace

Run with

python BRImage

Changelog

  • 0.2.2: Fixed segfault related bugs; cleaned code and implemented random walk for video feeds.
  • 0.2.1: Finished the video input feeds, and implementation for the frequency modulation part of video glitches. No CLI options for this available yet.
  • 0.2.0: Major refactor, favouring Feed derived classes as abstraction for image input.
  • 0.1.11: Staged some video I/O wrappers.
  • 0.1.10: Introduced numdevs contrasting parameter in frequency modulation.
  • 0.1.9: Updated CLI for all algorithms.
  • 0.1.8: RGB support added for random walk.
  • 0.1.7: Added random walk algorithm (greyscale only).
  • 0.1.6: Changed home-baked to SWIG wrapper.
  • 0.1.5: Home-baked C++ backend for the frequency modulation algorithm.

Uses ffmeg for Video I/O, pillow for Image I/O, numpy as the workhorse and black for formatting.


Todo:

  • phase damping option on frequency modulation
  • seed points for random walk