0

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)

  • You should try `cv2.COLOR_RGB2YCrCb`. – Burak Jul 09 '20 at 17:00
  • Tried it and it yields another value which is different from equation result. – BronzeCoin Jul 09 '20 at 17:14
  • I recommend adding both outputs and the input as well so that people can compare or reproduce the results manually. – Burak Jul 09 '20 at 18:55
  • The standard equations for conversion and what OpenCV does is slightly different. OpenCV calculates scaled and offset versions of the channels. See https://docs.opencv.org/3.4/de/d25/imgproc_color_conversions.html vs. https://en.wikipedia.org/wiki/YCbCr#JPEG_conversion – rayryeng Jul 09 '20 at 20:45
  • @rayryeng Checked both documentation. Does this mean value will always be different as OpenCV and manually checking has different equation? – BronzeCoin Jul 10 '20 at 08:58

1 Answers1

0

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