1
1
/*
2
2
* @name Histogram
3
3
* @description Calculates the histogram of an image.
4
- * A histogram is the frequency distribution of the gray levels with the number of
5
- * pure black values displayed on the left and number of pure white values on the right.
6
- * Note that this sketch will behave differently on Android, since most images will
4
+ * A histogram is the frequency distribution of the gray levels with the number of
5
+ * pure black values displayed on the left and number of pure white values on the right.
6
+ * Note that this sketch will behave differently on Android, since most images will
7
7
* no longer be full 24-bit color.
8
8
*/
9
9
@@ -21,7 +21,7 @@ function setup() {
21
21
image ( img , 0 , 0 ) ;
22
22
23
23
// Initialize the histogram
24
- for ( let i = 0 ; i < 256 ; i ++ ) {
24
+ for ( let i = 0 ; i < 100 ; i ++ ) {
25
25
hist . push ( 0 ) ;
26
26
}
27
27
@@ -40,8 +40,8 @@ function draw(){
40
40
stroke ( 255 ) ;
41
41
// Draw half of the histogram (skip every second value)
42
42
for ( let i = 0 ; i < img . width ; i += 2 ) {
43
- // Map i (from 0..img.width) to a location in the histogram (0..255 )
44
- let which = int ( map ( i , 0 , img . width , 0 , 255 ) ) ;
43
+ // Map i (from 0..img.width) to a location in the histogram (0..100 )
44
+ let which = int ( map ( i , 0 , img . width , 0 , 100 ) ) ;
45
45
// Convert the histogram value to a location between
46
46
// the bottom and the top of the picture
47
47
let y = int ( map ( hist [ which ] , 0 , histMax , img . height , 0 ) ) ;
0 commit comments