Convert BGR to RGB in seconds — enter values or paste a BGR hex string and get the RGB, hex, and OpenCV code instantly. No signup required.
What Is BGR vs RGB?
BGR and RGB store the exact same color information in reverse channel order. RGB lists a pixel’s color as red, then green, then blue. BGR lists the same three numbers as blue, then green, then red. A pixel that’s RGB(60, 26, 255) — a bright violet-red — is written as BGR(255, 26, 60) for the identical color, just with the first and third values swapped.
This isn’t a color space conversion the way RGB-to-HSL or RGB-to-LAB is. No math changes the color itself — only the order the three numbers are stored in changes. That’s the detail most explanations skip, and it’s the source of most BGR-related confusion.
Why Does BGR Exist?
BGR shows up because of legacy engineering decisions in a few specific places, not because it offers any technical advantage over RGB:
- OpenCV reads and displays images in BGR order by default, a decision inherited from early Windows-era camera and codec libraries.
- Windows Bitmap (BMP) files store pixel data in BGR order at the byte level.
- Some camera sensors and video codecs output raw frames in BGR to match the hardware pipeline they were originally built for.
If you’re debugging a Python computer-vision script and your colors look swapped — reds appearing as blues — a BGR/RGB mismatch is almost always the cause.
How to Convert BGR to RGB
Converting BGR to RGB means reversing the channel order, not recalculating anything. Given a BGR triplet (B, G, R), the RGB equivalent is simply (R, G, B).
Manually: Take your three values and write them in the opposite order. BGR(255, 0, 0) — where the first value is the blue channel — becomes RGB(0, 0, 255), since that same 255 now sits in the third (blue) position instead of the first.
In Python with OpenCV, the standard one-liner reverses the last axis of the image array:
rgb_image = bgr_image[:, :, ::-1]
Or, using OpenCV’s built-in conversion function:
import cv2
rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)
In JavaScript (Canvas/ImageData), swap the R and B bytes for every pixel in the data array:
for (let i = 0; i < imageData.data.length; i += 4) {
const r = imageData.data[i];
imageData.data[i] = imageData.data[i + 2];
imageData.data[i + 2] = r;
}
Common Mistake to Avoid
Treating BGR and RGB as visually different color models is the most common misunderstanding. They’re not. A BGR value and its correctly reordered RGB value render as the exact same color on screen. Bugs happen when code assumes an image is in RGB order but it’s actually BGR (or vice versa) — the pixel values don’t change, but they get interpreted incorrectly, which is what causes the classic “red and blue channels are swapped” visual bug in OpenCV projects.
FAQ
What is BGR vs RGB?
BGR and RGB represent the same color using the same three numbers, just in a different order. RGB stores channels as red, green, blue; BGR stores them as blue, green, red. The color itself doesn’t change — only which position each number occupies.
What does BGR to RGB mean?
Converting BGR to RGB means reordering a color’s three channel values from blue-green-red order to red-green-blue order. It’s a reformatting step, not a color transformation — the resulting color looks identical to the original.
How do you convert BGR to RGB?
Reverse the order of the three values: if you have BGR(B, G, R), the RGB equivalent is RGB(R, G, B). In OpenCV (Python), this is done with image[:, :, ::-1] or cv2.cvtColor(image, cv2.COLOR_BGR2RGB).
