From 622e8d23501a749be8338c800d2932dc832e7746 Mon Sep 17 00:00:00 2001 From: Madson Dias Date: Tue, 22 Sep 2026 06:25:12 -0300 Subject: [PATCH 1/2] fix yuv and luv color conversions --- caer/color/_luv.py | 10 +++++----- caer/color/_yuv.py | 10 +++++----- tests/color/test_luv.py | 6 ++++++ tests/color/test_yuv.py | 6 ++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/caer/color/_luv.py b/caer/color/_luv.py index 5d6ec2fe..8343754f 100644 --- a/caer/color/_luv.py +++ b/caer/color/_luv.py @@ -99,7 +99,7 @@ def luv2gray(tens: Tensor) -> Tensor: ) img = luv2bgr(tens) - img = bgr2gray(tens) + img = bgr2gray(img) return to_tensor(img, cspace="gray") @@ -124,7 +124,7 @@ def luv2hls(tens: Tensor) -> Tensor: ) img = luv2bgr(tens) - img = bgr2hls(tens) + img = bgr2hls(img) return to_tensor(img, cspace="hls") @@ -149,7 +149,7 @@ def luv2hsv(tens: Tensor) -> Tensor: ) img = luv2bgr(tens) - img = bgr2hsv(tens) + img = bgr2hsv(img) return to_tensor(img, cspace="hsv") @@ -174,7 +174,7 @@ def luv2lab(tens: Tensor) -> Tensor: ) img = luv2bgr(tens) - img = bgr2lab(tens) + img = bgr2lab(img) return to_tensor(img, cspace="lab") @@ -199,5 +199,5 @@ def luv2yuv(tens: Tensor) -> Tensor: ) img = luv2bgr(tens) - img = bgr2yuv(tens) + img = bgr2yuv(img) return to_tensor(img, cspace="yuv") diff --git a/caer/color/_yuv.py b/caer/color/_yuv.py index 6af0865c..a90f1e1b 100644 --- a/caer/color/_yuv.py +++ b/caer/color/_yuv.py @@ -99,7 +99,7 @@ def yuv2gray(tens: Tensor) -> Tensor: ) img = yuv2bgr(tens) - img = bgr2gray(tens) + img = bgr2gray(img) return to_tensor(img, cspace="gray") @@ -124,7 +124,7 @@ def yuv2hls(tens: Tensor) -> Tensor: ) img = yuv2bgr(tens) - img = bgr2hls(tens) + img = bgr2hls(img) return to_tensor(img, cspace="hls") @@ -149,7 +149,7 @@ def yuv2hsv(tens: Tensor) -> Tensor: ) img = yuv2bgr(tens) - img = bgr2hsv(tens) + img = bgr2hsv(img) return to_tensor(img, cspace="hsv") @@ -174,7 +174,7 @@ def yuv2lab(tens: Tensor) -> Tensor: ) img = yuv2bgr(tens) - img = bgr2lab(tens) + img = bgr2lab(img) return to_tensor(img, cspace="lab") @@ -199,5 +199,5 @@ def yuv2luv(tens: Tensor) -> Tensor: ) img = yuv2bgr(tens) - img = bgr2luv(tens) + img = bgr2luv(img) return to_tensor(img, cspace="luv") diff --git a/tests/color/test_luv.py b/tests/color/test_luv.py index 4b29dcf1..d7d8a26c 100644 --- a/tests/color/test_luv.py +++ b/tests/color/test_luv.py @@ -12,6 +12,7 @@ import caer import cv2 as cv import os +import numpy as np here = os.path.dirname(os.path.dirname(__file__)) tens_path = os.path.join(here, 'data', 'green_fish.jpg') @@ -50,6 +51,7 @@ def test_luv2gray(): assert len(gray.shape) == 2 or (len(gray.shape) == 3 and gray.shape[-1] == 1) assert isinstance(gray, caer.Tensor) assert gray.is_gray() + assert np.all(gray == cv.cvtColor(cv.cvtColor(cv_luv, cv.COLOR_LUV2BGR), cv.COLOR_BGR2GRAY)) def test_luv2hsv(): @@ -61,6 +63,7 @@ def test_luv2hsv(): assert len(hsv.shape) == 3 assert isinstance(hsv, caer.Tensor) assert hsv.is_hsv() + assert np.all(hsv == cv.cvtColor(cv.cvtColor(cv_luv, cv.COLOR_LUV2BGR), cv.COLOR_BGR2HSV)) def test_luv2hls(): @@ -72,6 +75,7 @@ def test_luv2hls(): assert len(hls.shape) == 3 assert isinstance(hls, caer.Tensor) assert hls.is_hls() + assert np.all(hls == cv.cvtColor(cv.cvtColor(cv_luv, cv.COLOR_LUV2BGR), cv.COLOR_BGR2HLS)) def test_luv2lab(): @@ -83,6 +87,7 @@ def test_luv2lab(): assert len(lab.shape) == 3 assert isinstance(lab, caer.Tensor) assert lab.is_lab() + assert np.all(lab == cv.cvtColor(cv.cvtColor(cv_luv, cv.COLOR_LUV2BGR), cv.COLOR_BGR2LAB)) def test_luv2yuv(): @@ -94,3 +99,4 @@ def test_luv2yuv(): assert len(yuv.shape) == 3 assert isinstance(yuv, caer.Tensor) assert yuv.is_yuv() + assert np.all(yuv == cv.cvtColor(cv.cvtColor(cv_luv, cv.COLOR_LUV2BGR), cv.COLOR_BGR2YUV)) diff --git a/tests/color/test_yuv.py b/tests/color/test_yuv.py index 7bdf27f1..84752fab 100644 --- a/tests/color/test_yuv.py +++ b/tests/color/test_yuv.py @@ -12,6 +12,7 @@ import caer import cv2 as cv import os +import numpy as np here = os.path.dirname(os.path.dirname(__file__)) tens_path = os.path.join(here, 'data', 'green_fish.jpg') @@ -50,6 +51,7 @@ def test_yuv2gray(): assert len(gray.shape) == 2 or (len(gray.shape) == 3 and gray.shape[-1] == 1) assert isinstance(gray, caer.Tensor) assert gray.is_gray() + assert np.all(gray == cv.cvtColor(cv.cvtColor(cv_yuv, cv.COLOR_YUV2BGR), cv.COLOR_BGR2GRAY)) def test_yuv2hsv(): @@ -61,6 +63,7 @@ def test_yuv2hsv(): assert len(hsv.shape) == 3 assert isinstance(hsv, caer.Tensor) assert hsv.is_hsv() + assert np.all(hsv == cv.cvtColor(cv.cvtColor(cv_yuv, cv.COLOR_YUV2BGR), cv.COLOR_BGR2HSV)) def test_yuv2hls(): @@ -72,6 +75,7 @@ def test_yuv2hls(): assert len(hls.shape) == 3 assert isinstance(hls, caer.Tensor) assert hls.is_hls() + assert np.all(hls == cv.cvtColor(cv.cvtColor(cv_yuv, cv.COLOR_YUV2BGR), cv.COLOR_BGR2HLS)) def test_yuv2lab(): @@ -83,6 +87,7 @@ def test_yuv2lab(): assert len(lab.shape) == 3 assert isinstance(lab, caer.Tensor) assert lab.is_lab() + assert np.all(lab == cv.cvtColor(cv.cvtColor(cv_yuv, cv.COLOR_YUV2BGR), cv.COLOR_BGR2LAB)) def test_yuv2luv(): @@ -94,3 +99,4 @@ def test_yuv2luv(): assert len(luv.shape) == 3 assert isinstance(luv, caer.Tensor) assert luv.is_luv() + assert np.all(luv == cv.cvtColor(cv.cvtColor(cv_yuv, cv.COLOR_YUV2BGR), cv.COLOR_BGR2LUV)) From 0706bf65f81eeadc00641db7e884f320be42811c Mon Sep 17 00:00:00 2001 From: Madson Dias Date: Wed, 23 Sep 2026 08:07:57 -0300 Subject: [PATCH 2/2] rename img to tens in yuv/luv color conversions --- caer/color/_luv.py | 38 +++++++++++++++++++------------------- caer/color/_yuv.py | 38 +++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/caer/color/_luv.py b/caer/color/_luv.py index 8343754f..69fc18bc 100644 --- a/caer/color/_luv.py +++ b/caer/color/_luv.py @@ -50,8 +50,8 @@ def luv2bgr(tens: Tensor) -> Tensor: "This function converts an LUV Tensor to its BGR counterpart" ) - img = cv.cvtColor(tens, LUV2BGR) - return to_tensor(img, cspace="bgr") + tens = cv.cvtColor(tens, LUV2BGR) + return to_tensor(tens, cspace="bgr") def luv2rgb(tens: Tensor) -> Tensor: @@ -74,8 +74,8 @@ def luv2rgb(tens: Tensor) -> Tensor: "This function converts a LUV Tensor to its RGB counterpart" ) - img = cv.cvtColor(tens, LUV2RGB) - return to_tensor(img, cspace="rgb") + tens = cv.cvtColor(tens, LUV2RGB) + return to_tensor(tens, cspace="rgb") def luv2gray(tens: Tensor) -> Tensor: @@ -98,9 +98,9 @@ def luv2gray(tens: Tensor) -> Tensor: "This function converts an LUV Tensor to its GRAY counterpart" ) - img = luv2bgr(tens) - img = bgr2gray(img) - return to_tensor(img, cspace="gray") + tens = luv2bgr(tens) + tens = bgr2gray(tens) + return to_tensor(tens, cspace="gray") def luv2hls(tens: Tensor) -> Tensor: @@ -123,9 +123,9 @@ def luv2hls(tens: Tensor) -> Tensor: "This function converts an LUV Tensor to its HLS counterpart" ) - img = luv2bgr(tens) - img = bgr2hls(img) - return to_tensor(img, cspace="hls") + tens = luv2bgr(tens) + tens = bgr2hls(tens) + return to_tensor(tens, cspace="hls") def luv2hsv(tens: Tensor) -> Tensor: @@ -148,9 +148,9 @@ def luv2hsv(tens: Tensor) -> Tensor: "This function converts an LUV Tensor to its HSV counterpart" ) - img = luv2bgr(tens) - img = bgr2hsv(img) - return to_tensor(img, cspace="hsv") + tens = luv2bgr(tens) + tens = bgr2hsv(tens) + return to_tensor(tens, cspace="hsv") def luv2lab(tens: Tensor) -> Tensor: @@ -173,9 +173,9 @@ def luv2lab(tens: Tensor) -> Tensor: "This function converts an LUV Tensor to its LAB counterpart" ) - img = luv2bgr(tens) - img = bgr2lab(img) - return to_tensor(img, cspace="lab") + tens = luv2bgr(tens) + tens = bgr2lab(tens) + return to_tensor(tens, cspace="lab") def luv2yuv(tens: Tensor) -> Tensor: @@ -198,6 +198,6 @@ def luv2yuv(tens: Tensor) -> Tensor: "This function converts an LUV Tensor to its YUV counterpart" ) - img = luv2bgr(tens) - img = bgr2yuv(img) - return to_tensor(img, cspace="yuv") + tens = luv2bgr(tens) + tens = bgr2yuv(tens) + return to_tensor(tens, cspace="yuv") diff --git a/caer/color/_yuv.py b/caer/color/_yuv.py index a90f1e1b..b628dfd5 100644 --- a/caer/color/_yuv.py +++ b/caer/color/_yuv.py @@ -50,8 +50,8 @@ def yuv2bgr(tens: Tensor) -> Tensor: "This function converts an YUV Tensor to its BGR counterpart" ) - img = cv.cvtColor(tens, YUV2BGR) - return to_tensor(img, cspace="bgr") + tens = cv.cvtColor(tens, YUV2BGR) + return to_tensor(tens, cspace="bgr") def yuv2rgb(tens: Tensor) -> Tensor: @@ -74,8 +74,8 @@ def yuv2rgb(tens: Tensor) -> Tensor: "This function converts a YUV Tensor to its RGB counterpart" ) - img = cv.cvtColor(tens, YUV2RGB) - return to_tensor(img, cspace="rgb") + tens = cv.cvtColor(tens, YUV2RGB) + return to_tensor(tens, cspace="rgb") def yuv2gray(tens: Tensor) -> Tensor: @@ -98,9 +98,9 @@ def yuv2gray(tens: Tensor) -> Tensor: "This function converts an YUV Tensor to its GRAY counterpart" ) - img = yuv2bgr(tens) - img = bgr2gray(img) - return to_tensor(img, cspace="gray") + tens = yuv2bgr(tens) + tens = bgr2gray(tens) + return to_tensor(tens, cspace="gray") def yuv2hls(tens: Tensor) -> Tensor: @@ -123,9 +123,9 @@ def yuv2hls(tens: Tensor) -> Tensor: "This function converts an YUV Tensor to its HLS counterpart" ) - img = yuv2bgr(tens) - img = bgr2hls(img) - return to_tensor(img, cspace="hls") + tens = yuv2bgr(tens) + tens = bgr2hls(tens) + return to_tensor(tens, cspace="hls") def yuv2hsv(tens: Tensor) -> Tensor: @@ -148,9 +148,9 @@ def yuv2hsv(tens: Tensor) -> Tensor: "This function converts an YUV Tensor to its HSV counterpart" ) - img = yuv2bgr(tens) - img = bgr2hsv(img) - return to_tensor(img, cspace="hsv") + tens = yuv2bgr(tens) + tens = bgr2hsv(tens) + return to_tensor(tens, cspace="hsv") def yuv2lab(tens: Tensor) -> Tensor: @@ -173,9 +173,9 @@ def yuv2lab(tens: Tensor) -> Tensor: "This function converts an YUV Tensor to its LAB counterpart" ) - img = yuv2bgr(tens) - img = bgr2lab(img) - return to_tensor(img, cspace="lab") + tens = yuv2bgr(tens) + tens = bgr2lab(tens) + return to_tensor(tens, cspace="lab") def yuv2luv(tens: Tensor) -> Tensor: @@ -198,6 +198,6 @@ def yuv2luv(tens: Tensor) -> Tensor: "This function converts an YUV Tensor to its LUV counterpart" ) - img = yuv2bgr(tens) - img = bgr2luv(img) - return to_tensor(img, cspace="luv") + tens = yuv2bgr(tens) + tens = bgr2luv(tens) + return to_tensor(tens, cspace="luv")