GRK TUT2 Task5
by linoskoczek
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
<script type="text/javascript">
function preload() {
img = loadImage("https://raw.githubusercontent.com/scikit-image/scikit-image/master/skimage/data/astronaut.png");
}
function setup() {
createCanvas(512,512);
img.resize(256,256);
img.loadPixels();
img.filter('gray');
var arr = (new Array(10)).fill(0);
var histogram = (new Array(256)).fill(0);
for(x=0;x<img.width;x++) {
for(y=0;y<img.height;y++) {
pos=4*(y*img.width+x);
histogram[img.pixels[pos+2]] += 1;
}
}
background(255);
maxx = Math.max.apply(null, histogram);
console.log("max" + maxx);
for(x = 0; x < 256; x++) {
line(x, 256, x, 256 - histogram[x]/maxx*256.0*9);
}
console.log(histogram[0]/256);
}
</script>