'How to change image from gray scale format into RGB format
Solution 1:[1]
I don't think this is possible, a grayscale image has just one channel (shades of gray), while, BGR (default color space in opencv, or BGRA if on mac)just like RGB has three channels (RED GREEN BLUE), you can convert it into grayscale using this formula:
Y = 0.299 R + 0.587 G + 0.114 B
where Y is the one channel of grayscale image. But you can't do the vice versa. Grayscale is basically just different shades of gray. You can't do the reverse. In RGB/BGR a pixel looks like this [R,G,B] which is somewhat like an array, whereas in grayscale it is just a single value. We often consider value < 100 as black in grayscale.
Image is often reprsented in form of an array (np.array in case of python), and the thing is, in most of the arrays, you can't modify the dimensions. Like np.array has an attribute called shape which tells us about the dimensions of the array, or in an image think of it like resolution. Shape of a grayscale image looks like this (RESOLUTION-Y, RESOLUTION-X), which means it's a 2d matrix/array and one pixel is represented by a single value, whereas in RGB/BGR, the shape looks like this, (RESOLUTION-Y, RESOLUTION-X, 3), so it's a 3d array, where 3 is the number of channels.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


