Javatpoint Logo
Javatpoint Logo

Grayscale to RGB Conversion

To convert a grayscale image into color or RGB format, we have two methods. Both methods have their advantages as well as disadvantages.

Methods for conversion of grayscale image to RGB are as following:

1. Average method

It is the simplest method. We have to take an average of all the 3 colors.

Formula: (R + G + B)/3

For example:

Grayscale to RGB Conversion Grayscale to RGB Conversion

Explanation

As we can see, there are changes in the image by applying the average method. But the result is unexpected as we want a grayscale image, but it turned to be a black image.

Problem

This problem occurs because we have taken an average of 3 colors. All the 3 colors have different wavelength and have their contribution to the formation of an image. In the above image, we are taking 33% from each portion that is why the image does not occur in grayscale.

The solution to this problem is given by the weighted method.

Weighted method or luminosity method

As we have seen the problem in the average method. And for this problem weight method is the solution. In all the 3 portions of color, red color has more wavelength, and green color has less wavelength. But green color gives a more soothing effect to the eyes as compared to red color.

By decreasing the value of red color and increasing the value of green color and the value for blue color will be between these two colors.

The equation for a new grayscale image will be:

Let the new grayscale image be X

Grayscale to RGB Conversion

According to the above equation, red is used 30%, green is used 59%, and blue is used 11%. The contribution of green is highest.

By Applying the equation in an image, we will get:

Grayscale to RGB Conversion Grayscale to RGB Conversion

Explanation

As we can see using the weighted method the image is properly converted into grayscale. Image is brighter as compared with the image which was generated using the average method.






Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA