Reputation: 32091
Lets say I have an int[][] arrayA
and an int[][] arrayB
. At any given coordinate in this array lies an RGB value. What I want to do is merge the RGB values from arrayA
and array
2 into a new array, newArray
, using a weighted average method.
So what I'm doing is extracting the red, green, and blue values from each RGB value like this:
curColA=RGB //suppose RGB is just the RGB in any given point
int curRedA = (curCol >> 16) & 0xFF;
int curGreenA = (curCol >> 8) & 0xFF;
int curBlueA= curCol & 0xFF;
I do the same for arrayB, and now I want to merge them. Here's where I'm having trouble. Do I just do newRed=(curRedA+curRedB)/2
or is there some other way to do this?
arrayA values: { { 0, 0x44, 0x5500, 0x660000 } };
arrayB values: { { 2, 4, 6, 8 } };
newArray expected values: { 0, 0x44, 6, 0x660000 } };
Upvotes: 1
Views: 781
Reputation: 41862
A weighted average is usually done something like:
newRed = (curRedA * redWeight + curRedB * (1 - redWeight));
...where redWeight
is in the range [0, 1], and represents the weight (or bias) towards red values in the 'A' array. It also represents the inverse of the bias toward the red values in the 'B' array.
Upvotes: 1