You're probably trying to convert to grayscale. There are two things you should do:
- Your weights are wrong. The correct weights are 0.299, 0.587 and 0.114.
Apply a cap using
Math.Min()
. Something like:Y1[x, y] = Math.Min(255, Convert.ToInt32(0.299 * R[x, y] + 0.587 * G[x, y] + 0.114 * B[x, y]));
The cap is there only to make sure our formula never exceeds the max byte value.