Created
October 26, 2020 11:09
-
-
Save gordinmitya/d2e79741f7986ed247063738857b5f1b to your computer and use it in GitHub Desktop.
rgb, ycbcr, opencv, numpy, skimage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import skimage.color | |
import torch | |
rgb2ycbcr = np.array([[65.481, 128.553, 24.966], | |
[-37.797, -74.203, 112.0], | |
[112.0, -93.786, -18.214]]).T | |
# from scipy import linalg | |
# rgb_from_ycbcr = linalg.inv(ycbcr_from_rgb) | |
ycbcr2rgb = np.array([[4.56621005e-03, 1.18087999e-09, 6.25892897e-03], | |
[4.56621005e-03, -1.53632369e-03, -3.18811095e-03], | |
[4.56621005e-03, 7.91071623e-03, 1.19774970e-08]]) | |
img = (np.ones((2,2,3)) * 255).astype(np.uint8) | |
img[..., 0] *= 1 | |
img[..., 1] *= 2 | |
img[..., 2] *= 3 | |
# img = cv2.imread('../images/butterfly.png') | |
mul = np.matmul(img / 255.0, rgb2ycbcr) | |
mul[..., 0] += 16 | |
mul[..., 1] += 128 | |
mul[..., 2] += 128 | |
print('matmul', mul) | |
print('ski', skimage.color.rgb2ycbcr(img)) | |
print('opencv', cv2.cvtColor(img, cv2.COLOR_RGB2YCrCb)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output