Skip to content

Instantly share code, notes, and snippets.

@jonkeegan
Last active July 11, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonkeegan/f394e9f633c5625b9a8f to your computer and use it in GitHub Desktop.
Save jonkeegan/f394e9f633c5625b9a8f to your computer and use it in GitHub Desktop.
This is a snippet of code to render histograms from a bitmap to json. I used this technique in this project: http://graphics.wsj.com/avengers/
// requires ImageMagick (http://www.imagemagick.org/) and csvkit (https://github.com/onyxfish/csvkit)
// You need to have a schmea csv file like this in the same directory:histogram_schema.csv
column,start,length
count,0,10
color,26,7
// This takes a color bitmap, turns it to 64 colors (to keep it a resonable size), generates a histogram, exports the colors and counts to a json object
convert my_bitmap.png -dither Riemersma -colors 64 -format %c histogram:info:- | in2csv -f fixed -s histogram_schema.csv | csvjson > 397.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment