Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is BGR color space?

An RGB color is composed of three components: Red (0-255), Green (0-255) and Blue (0-255).

What exactly is BGR color space? How is it different from RGB color space?

like image 812
user43076 Avatar asked Dec 15 '08 04:12

user43076


People also ask

What is BGR color space?

BGR stands for Blue(255, 0, 0), Green(0, 255, 0), Red(0, 0, 255). OpenCV uses BGR color as a default color space to display images, when we open a image in openCV using cv2. imread() it display the image in BGR format. And it provides color-changing methods using cv2.

What is the difference between BGR and RGB?

What's the Difference between RGB versus BGR? The main difference between RGB versus BGR is the arrangement of the subpixels for Red, Green, and Blue. RGB is arranged like that, but BGR is essentially in reverse with no adverse effect on color vibrancy and accuracy.

Why does OpenCV use BGR instead of RGB?

OpenCV reads in images in BGR format (instead of RGB) because when OpenCV was first being developed, BGR color format was popular among camera manufacturers and image software providers.

Why do we convert BGR to RGB?

Converting a BGR image to RGB and vice versa can have several reasons, one of them being that several image processing libraries have different pixel orderings.


1 Answers

Its about endianness.

RGB is a byte-order. But a deliberate implementation choice of most vanilla Graphics libraries is that they treat colours as unsigned 32-bit integers internally, with the three (or four, as alpha is typically included) components packed into the integer.

On a little-endian machine (such as x86) the integer 0x01020304 will actually be stored in memory as 0x04030201. And thus 0x00BBGGRR will be stored as 0xRRGGBB00!

So the term BGR (and BGRA etc) is a leaky abstraction where the graphics library is explaining how the integer is logically ordered, so as to make your code that is directly accessing the colour components individually more readable.

Remember that bitmaps are usually accessed by more parts of the hardware than your processor, and the endian that is specified by, say, conventional display adapters, is not necessarily the same as the endian of your CPU. At the level of manipulating the channels in the pixel its no problem for a CPU to extract the fields whatever their order; its purely a programmer understanding the labelling thing.

like image 125
Will Avatar answered Sep 22 '22 21:09

Will