summing red() green() and blue() values
in
Programming Questions
•
2 months ago
hi there,
i have been working on a pixel averaging project, and have two ways of generating an average that to my eyes seem equivalent, but have not been producing equivalent results. i think i've been staring at it for far too long, so if anyone can see the reason, i'd be extremely grateful.
thanks!
method 1:
r = (red(pc0) + red(pc1) + red(pc2) + red(pc3) + red(pc4)) / 5;
g = (green(pc0) + green(pc1) + green(pc2) + green(pc3) + green(pc4)) / 5;
b = (blue(pc0) + blue(pc1) + blue(pc2) + blue(pc3) + blue(pc4)) / 5;
method 2:
r = r + red(pc0);
r = r + red(pc1);
r = r + red(pc2);
r = r + red(pc3);
r = r + red(pc4);
g = g + green(pc0);
g = g + green(pc1);
g = g + green(pc2);
g = g + green(pc3);
g = g + green(pc4);
b = b + blue(pc0);
b = b + blue(pc1);
b = b + blue(pc2);
b = b + blue(pc3);
b = b + blue(pc4);
r = r / 5;
g = g / 5;
b = b / 5;
note: the general version of this, using arrays, produces a result equivalent to method 2.
1