I would like to fade the color of a pixel out toward white, but obviously maintain the same color. If I have a pixel (200,120,40)
, will adding 10 to each value to m
I prefer to use HSV color mode.
To grayer your color you have to decrease Saturation factor.
Standard colorsys module can help in RGB <-> HSV conversions, but please keep in mind: colorsys
operates with channel values in range [0, 1), not [0, 256).
There is full code example:
>>> from colorsys import hsv_to_rgb, rgb_to_hsv
>>> color = (200, 120, 40)
>>> normalized_color = (color[0]/256., color[1]/256., color[2]/256.)
>>> normalized_color
(0.78125, 0.46875, 0.15625)
>>> hsv_color = rgb_to_hsv(*normalized_color)
>>> hsv_color
(0.08333333333333333, 0.8, 0.78125)
>>> grayed_hsv_color = (hsv_color[0], 0.6, hsv_color[2])
>>> grayed_rgb_color = hsv_to_rgb(*grayed_hsv_color)
>>> grayed_rgb_color
(0.78125, 0.546875, 0.3125)
>>> denormalized_rgb_color = (int(grayed_rgb_color[0]*256), int(grayed_rgb_color[1]*256), int(grayed_rgb_color[2]*256))
>>> denormalized_rgb_color
(200, 140, 80)