def ycbcr2rgb(img, only_y=True):
    '\n    bgr version of matlab ycbcr2rgb\n    Python opencv library (cv2) cv2.COLOR_YCrCb2BGR has\n    different parameters to MATLAB color convertion.\n\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
    mat = np.array([[24.966, 128.553, 65.481], [112, (- 74.203), (- 37.797)], [(- 18.214), (- 93.786), 112.0]])
    mat = (np.linalg.inv(mat.T) * 255)
    offset = np.array([[[16, 128, 128]]])
    rlt = np.dot((img_ - offset), mat)
    rlt = np.clip(rlt, 0, 255)
    if (in_img_type == np.uint8):
        rlt = rlt.round()
    else:
        rlt /= 255.0
    return rlt.astype(in_img_type)
bgr version of matlab ycbcr2rgb
Python opencv library (cv2) cv2.COLOR_YCrCb2BGR has
different parameters to MATLAB color convertion.

Input:
    uint8, [0, 255]
    float, [0, 1]
def ycbcr2rgb(img, only_y=True):
    '\n    bgr version of matlab ycbcr2rgb\n    Python opencv library (cv2) cv2.COLOR_YCrCb2BGR has\n    different parameters to MATLAB color convertion.\n\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
    mat = np.array([[24.966, 128.553, 65.481], [112, (- 74.203), (- 37.797)], [(- 18.214), (- 93.786), 112.0]])
    mat = (np.linalg.inv(mat.T) * 255)
    offset = np.array([[[16, 128, 128]]])
    rlt = np.dot((img_ - offset), mat)
    rlt = np.clip(rlt, 0, 255)
    if (in_img_type == np.uint8):
        rlt = rlt.round()
    else:
        rlt /= 255.0
    return rlt.astype(in_img_type)