moyix / vidcolortree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VidColorTree

This script analyzes the colors used in a video file, identifies the most prominent K colors (configurable; grouped using K-Means), and then plots them as a treemap.

Gallery

Here are samples of some well-known colorful movies generated by VidColorTree:

Movie 256 colors, threshold 30, percent 30 32 colors, threshold 30, percent 30
Amélie (2001) Amélie (2001) Amélie (2001)
Avatar (2009) Avatar (2009) Avatar (2009)
Life of Pi (2012) Life of Pi (2012) Life of Pi (2012)
The Grand Budapest Hotel (2014) The Grand Budapest Hotel (2014) The Grand Budapest Hotel (2014)
The Matrix (1999) The Matrix (1999) The Matrix (1999)

Setup

You should be able to just run pip install -r requirements.txt.

Usage


usage: vid_hist.py [-h] [-d OUTPUT_DIR] [-c COLORS] [-f] [-b {opencv,pyav}]
                   [-i] [-m {kmeans,mbkmeans}] [-s SEED] [-t THRESHOLD]
                   [-p PERCENT] [-V] [-D]
                   vid_filename

Video Histogram

positional arguments:
  vid_filename          Video file to process

optional arguments:
  -h, --help            show this help message and exit
  -d OUTPUT_DIR, --output_dir OUTPUT_DIR
                        Output directory
  -c COLORS, --colors COLORS
                        Number of colors to use
  -f, --force           Force recomputation of the histogram
  -b {opencv,pyav}, --backend {opencv,pyav}
                        Which backend to use (PyAV or OpenCV)
  -i, --iframes         Only look at I-frames
  -m {kmeans,mbkmeans}, --method {kmeans,mbkmeans}
                        Which clustering algorithm to use (K-Means or
                        MiniBatchKMeans)
  -s SEED, --seed SEED  Random seed for K-Means
  -t THRESHOLD, --threshold THRESHOLD
                        Ignore colors that are within this distance of
                        black/white (Euclidean)
  -p PERCENT, --percent PERCENT
                        Ignore colors that are more than this percent of the
                        video
  -V, --verbose         Enable info messages
  -D, --debug           Enable debug messages

Tips

  • If your generated image has big black boxes, you may want to try using the -t (threshold) and -p (percent) options to remove colors that are too close to black/white and to remove any colors that occupy more than some percentage of the palette, respectively.

  • Depending on the video, it may be faster to just sample I-frames. However, this seems to break on some videos (finding very few frames).

About

License:MIT License


Languages

Language:Python 100.0%