If the gray scale value is updated in the RGB components of
the colored vector then that particular shade will be in gray scale as shown
below.

The value 61 is updated in Red, Green and Blue
components. Similarly, 106 and 83 are also updated.

Using this principle, we can use both RGB and gray color in
a single image to obtain a partially colored gray scale image.

Let us now learn how to obtain partially colored gray scale
image.

Step 1: Read the input RGB image and its corresponding RGB components

1.Read an RGB Image

2.Store the Red component in matrix R, Green in matrix
G and Blue in matrix B.

Step 2: Define the
Grayscale Image

1.Convert RGB Image to Grayscale Image (GS)

2.Create a matrix R1, G1 and B1 of the same size
of matrix R, G and B

3.Update the matrices R1,G1 and B1 with the value
of the matrix GS

Step 3: Create a Mask

1.Create a matrix of size GS

2.Update the pixel positions with one if the pixel
position should be RGB else zero or vice versa.

Step 4: Find the
index of the masked positions from the Mask

Step 5: Create
partial color and gray scale

1.Obtain the Red component (R) for the
corresponding index of the mask and update it in the R1 matrix. Similarly,
update the other matrices G1 and B1 with values of G and B matrices based on
the index of the mask.

2.Create a Three dimensional matrix of the same
size of RGB Image

3.Update the three dimensional matrix with the R1,
G1 and B1 components. This is the required partially coloured gray scale image.