From 00bc1b4fdf218f33aaa3e41ff308b2aab5c2981a Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Sat, 14 Dec 2019 12:55:46 +0200 Subject: [PATCH] ycbcr2rgb --- python/ftl/ftlstream.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/python/ftl/ftlstream.py b/python/ftl/ftlstream.py index 103a53c96..75aa4406d 100644 --- a/python/ftl/ftlstream.py +++ b/python/ftl/ftlstream.py @@ -25,7 +25,7 @@ except ImportError: ''' YCrCb to RGB, based on OpenCV documentation definition. Note: It seems this implementation is not perfectly equivalent to - OpenCV's + OpenCV's (results not exactly same, why?) ''' rgb = np.zeros(img.shape, np.float) @@ -41,6 +41,20 @@ except ImportError: return rgb.round().astype(np.uint8) +def _ycbcr2rgb(img): + rgb = np.zeros(img.shape, np.float) + + Y = img[:,:,0].astype(np.float) + Cr = img[:,:,2].astype(np.float) + Cb = img[:,:,1].astype(np.float) + delta = 128.0 + + rgb[:,:,0] = Y + 1.403 * (Cr - delta) + rgb[:,:,1] = Y - 0.714 * (Cr - delta) - 0.344 * (Cb - delta) + rgb[:,:,2] = Y + 1.773 * (Cb - delta) + + return rgb.round().astype(np.uint8) + class FTLStreamWriter: def __init__(self, file, version=2): self._file = open(file, "wb") @@ -237,7 +251,7 @@ class FTLStreamReader: if self._version < 3: self._frame = _ycrcb2rgb(img) else: - self._frame = img + self._frame = _ycbcr2rgb(img) def _decode_opencv(self, sp, p): try: -- GitLab