def bgr2ycbcr(img, only_y=True, separate=False):
    'bgr version of matlab rgb2ycbcr\n    Python opencv library (cv2) cv2.COLOR_BGR2YCrCb has\n    different parameters with MATLAB color convertion.\n    only_y: only return Y channel\n    separate: if true, will returng the channels as\n        separate images\n    Input:\n        uint8, [0, 255]\n        float, [0, 1]\n    '
    in_img_type = img.dtype
    img_ = img.astype(np.float32)
    if (in_img_type != np.uint8):
        img_ *= 255.0
    if only_y:
        rlt = ((np.dot(img_, [24.966, 128.553, 65.481]) / 255.0) + 16.0)
    else:
        rlt = ((np.matmul(img_, [[24.966, 112.0, (- 18.214)], [128.553, (- 74.203), (- 93.786)], [65.481, (- 37.797), 112.0]]) / 255.0) + [16, 128, 128])
    if (in_img_type == np.uint8):
        rlt = rlt.round()
    else:
        rlt /= 255.0
    if separate:
        rlt = rlt.astype(in_img_type)
        return (rlt[:, :, 0], rlt[:, :, 1], rlt[:, :, 2])
    else:
        return rlt.astype(in_img_type)
bgr version of matlab rgb2ycbcr
Python opencv library (cv2) cv2.COLOR_BGR2YCrCb has
different parameters with MATLAB color convertion.
only_y: only return Y channel
separate: if true, will returng the channels as
    separate images
Input:
    uint8, [0, 255]
    float, [0, 1]
def bgr2ycbcr(img, only_y=True, separate=False):
    'bgr version of matlab rgb2ycbcr\n    Python opencv library (cv2) cv2.COLOR_BGR2YCrCb has\n    different parameters with MATLAB color convertion.\n    only_y: only return Y channel\n    separate: if true, will returng the channels as\n        separate images\n    Input:\n        uint8, [0, 255]\n        float, [0, 1]\n    '
    in_img_type = img.dtype
    img_ = img.astype(np.float32)
    if (in_img_type != np.uint8):
        img_ *= 255.0
    if only_y:
        rlt = ((np.dot(img_, [24.966, 128.553, 65.481]) / 255.0) + 16.0)
    else:
        rlt = ((np.matmul(img_, [[24.966, 112.0, (- 18.214)], [128.553, (- 74.203), (- 93.786)], [65.481, (- 37.797), 112.0]]) / 255.0) + [16, 128, 128])
    if (in_img_type == np.uint8):
        rlt = rlt.round()
    else:
        rlt /= 255.0
    if separate:
        rlt = rlt.astype(in_img_type)
        return (rlt[:, :, 0], rlt[:, :, 1], rlt[:, :, 2])
    else:
        return rlt.astype(in_img_type)