Last active
July 11, 2018 16:03
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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