Why converting BGR to YCbCr in OpenCV inherit different value compared to manually counting it using equation?

605 views Asked by At

I tried to check whether my image conversion have the same RGB value as manually converting using RGB to YCbCr equation. Using python :

import cv2
import numpy as np

file_src='rgb_color.bmp' //input image
file_dst='ycbcr_color.bmp' //output image

img_src=cv2.imread(file_src,1) //read input image

cv2.namedWindow('src')
cv2.namedWindow('dst')

img_dst=cv2.cvtColor(img_src,cv2.COLOR_BGR2YCrCb)

cv2.imshow('src',img_src)
cv2.imshow('dst',img_dst)
cv2.imwrite(file_dst,img_dst) //write output file as ycbcr_color.bmp
cv2.waitKey(0)
cv2.destoyAllWindows()

which succesfully convert RGB image to supposedly YCrCb
(with value of 85 255 76 43 21 150 255 107 29 128 128 255) while manually using equation and converting them to image yield me this (with value of 82 90 240 145 54 34 41 240 110 235 128 128).

Does the fact that OpenCV read RGB as BGR affect this? or does OpenCV read YCbCr as YCrCb (judging at cv2.COLOR_BGR2YCrCb)

1

There are 1 answers

0
BronzeCoin On

For future google user:

The standard equations for conversion and what OpenCV does is slightly different. OpenCV calculates scaled and offset versions of the channels. See docs.opencv.org/3.4/de/d25/imgproc_color_conversions.html vs. en.wikipedia.org/wiki/YCbCr#JPEG_conversion – rayryeng