To convert a color from a colorspace based on a typical gamma-compressed (nonlinear) RGB color model to a grayscale representation of its luminance, the gamma compression function must first be removed via gamma expansion (linearization) to transform the image to a linear RGB colorspace, so that the appropriate weighted sum can be applied to the linear color components (formula_1) to calculate the linear luminance , which can then be gamma-compressed back again if the grayscale result is also to be encoded and stored in a typical nonlinear colorspace.