i have to following code taken from the complete reference
it about the following syntax:- " hist[y]++; " which appears there its about creating histogram of brightness values of img.
i wonder what it means in the code since hist[] is defined as int[256] , while the itteration here is much larger then 256.
int hist[] = new int[256]; <<<<<<<<defined here 256 elements
...
for (int i=0; i<iw*ih; i++) {
int p = pixels[i];
int r = 0xff & (p >> 16);
int g = 0xff & (p >> 8);
int b = 0xff & (p);
int y = (int) (.33 * r + .56 * g + .11 * b);
hist[y]++; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here many more elements
}
etc. etc..
hist[y]++;
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< here many more elements
You're perhaps mixing up the expression hist[y]++
with hist[y++]
or confusing y
with the loop index i
.
The expression hist[y]++
simply increments the value at index y
by one. And the index y
is set in the line above to
int y = (int) (.33 * r + .56 * g + .11 * b);
Since r
, g
and b
are all <= 255
the maximum value of y
is
.33*255 + .56*255 + .11*255
= (.33 + .56 + .11) * 255
= 1 * 255
so an array of 256 elements will suffice.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments