change ToGrayscale() to be ToColor(int mask), so instead of giving the average brightness to each color, it gives it to the ones that match the mask and sets the other colors' brightnesses to 0.