Experiment in generating images and audio using markov chains
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
audio
.gitignore
README.md
imggen.py
requirements.txt
setup.py

README.md

Markov Chain Image Generation

This is a small script that generates images from other images using a markov chain.

Dependencies

Install using pip install -r requirements.txt

You will need:

  • Python 3
  • numpy
  • pillow
  • requests
  • scipy
  • pyprind

If you want to try the audio generation, you will need:

  • scipy
  • keras
  • matplotlib
  • sounddevice

Usage

To use the image generator, you can provide either a local file or remote url:

usage: imggen.py [-h] -i INPUT [-b BUCKETS] [-ow WIDTH] [-oh HEIGHT] [-n] [-d]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Image to learn from. Can be a local file or url
  -b BUCKETS, --buckets BUCKETS
                        Training bucket width
  -ow WIDTH, --width WIDTH
                        Width of output image
  -oh HEIGHT, --height HEIGHT
                        Height of output image
  -n, --eight-neighbours
                        Train on all 8 neighbours, default is 4
  -d, --directional     Train the image using the relative location of each
                        neighbour
  -s, --show-normalized Show the normalized (just apply the bucketing) image only

The most basic example is:

./imggen.py -i img.jpg

Here is an example using an image url with 720x720 output, buckets of width 8, train on all 8 neighbours and learn the direction of colours:

./imggen.py -i https://i.imgur.com/Er2xlip.jpg -oh 720 -ow 720 -b 8 -n -d

Examples

HomerInput HomerGenerated

An image generated from my black and white portrait:

MeGenerated

Audio Generation

These scripts are incomplete attempts at generating audio using a markov chain from a raw PCM stream. The best I could get was a constant tone, which beat the previous outputs of what was essentially noise.