π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Avoid openCV in the tests
Pau4ae1439def16
diff --git a/test/color/test_hls.py b/test/color/test_hls.pyindex 31406578a..e4e29fd0b 100644--- a/test/color/test_hls.py+++ b/test/color/test_hls.py@@ -5,9 +5,7 @@ import kornia.testing as utils # test utilsfrom kornia.geometry import pifrom test.common import device_type-import cv2import math-import numpy as npimport torchfrom torch.autograd import gradcheck@@ -18,15 +16,40 @@ class TestRgbToHls:def test_rgb_to_hls(self):- data = torch.rand(3, 5, 5)+ data = torch.Tensor([[[0.4237059, 0.1935902, 0.8585021, 0.3790484, 0.1389151],+ [0.5933651, 0.0474544, 0.2801555, 0.1691061, 0.9221829],+ [0.2351739, 0.5852075, 0.5789326, 0.8411915, 0.5960411],+ [0.0290176, 0.6459382, 0.8581501, 0.4755400, 0.7735767],+ [0.9497226, 0.0919441, 0.5462211, 0.7836787, 0.6403612]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0)- expected = cv2.cvtColor(data_cv, cv2.COLOR_RGB2HLS)+ [[0.2280025, 0.1352853, 0.7999730, 0.6658246, 0.4910861],+ [0.3499791, 0.1250734, 0.6315800, 0.4785843, 0.8477826],+ [0.3646359, 0.2415122, 0.5301932, 0.0782518, 0.8710389],+ [0.6957581, 0.6162295, 0.6259052, 0.1753750, 0.6737530],+ [0.7678874, 0.9825978, 0.0234877, 0.2485284, 0.8159551]],++ [[0.7330830, 0.9015747, 0.0229067, 0.4280063, 0.5400181],+ [0.0037299, 0.3259412, 0.3467951, 0.9575506, 0.1525899],+ [0.9660432, 0.5287710, 0.6654660, 0.3797526, 0.4981400],+ [0.7422802, 0.9926301, 0.5334370, 0.7852844, 0.4397180],+ [0.2281681, 0.2560037, 0.5134379, 0.5800887, 0.8685090]]])- h_expected = 2 * math.pi * expected[:, :, 0] / 360.- l_expected = expected[:, :, 1]- s_expected = expected[:, :, 2]+ # OpenCV+ h_expected = torch.Tensor([[4.5945477, 4.268469, 0.9738468, 2.2731707, 3.269344],+ [0.6149417, 3.8969188, 2.292972, 3.7777472, 0.9459598],+ [4.003296, 5.4079432, 4.566101, 5.869351, 1.8194631],+ [3.2098956, 4.271444, 0.29820946, 4.7041655, 0.7340856],+ [0.78329855, 2.2872903, 5.3016634, 5.634379, 3.382815]])+ l_expected = torch.Tensor([[0.48054275, 0.51843, 0.44070444, 0.5224365, 0.33946657],+ [0.2985475, 0.18669781, 0.45586777, 0.5633283, 0.5373864],+ [0.6006086, 0.41335985, 0.5978296, 0.45972168, 0.6845894],+ [0.38564888, 0.80442977, 0.6957935, 0.48032972, 0.6066474],+ [0.5889454, 0.53727096, 0.2848544, 0.5161035, 0.7544351]])+ s_expected = torch.Tensor([[0.5255313, 0.79561585, 0.9480225, 0.30024928, 0.59078425],+ [0.98750657, 0.7458223, 0.3854456, 0.90278864, 0.8317882],+ [0.9149786, 0.4157338, 0.16817844, 0.82978433, 0.5911325],+ [0.9247565, 0.9623155, 0.53370523, 0.63488615, 0.4243758],+ [0.8776869, 0.96239233, 0.91754496, 0.55295944, 0.46453667]])# Korniaf = kornia.color.RgbToHls()@@ -42,35 +65,58 @@ class TestRgbToHls:def test_batch_rgb_to_hls(self):- data = torch.rand(3, 5, 5)+ data = torch.Tensor([[[0.4237059, 0.1935902, 0.8585021, 0.3790484, 0.1389151],+ [0.5933651, 0.0474544, 0.2801555, 0.1691061, 0.9221829],+ [0.2351739, 0.5852075, 0.5789326, 0.8411915, 0.5960411],+ [0.0290176, 0.6459382, 0.8581501, 0.4755400, 0.7735767],+ [0.9497226, 0.0919441, 0.5462211, 0.7836787, 0.6403612]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0)- expected = cv2.cvtColor(data_cv, cv2.COLOR_RGB2HLS)+ [[0.2280025, 0.1352853, 0.7999730, 0.6658246, 0.4910861],+ [0.3499791, 0.1250734, 0.6315800, 0.4785843, 0.8477826],+ [0.3646359, 0.2415122, 0.5301932, 0.0782518, 0.8710389],+ [0.6957581, 0.6162295, 0.6259052, 0.1753750, 0.6737530],+ [0.7678874, 0.9825978, 0.0234877, 0.2485284, 0.8159551]],- expected[:, :, 0] = 2 * math.pi * expected[:, :, 0] / 360.- expected = expected.transpose(2, 0, 1)+ [[0.7330830, 0.9015747, 0.0229067, 0.4280063, 0.5400181],+ [0.0037299, 0.3259412, 0.3467951, 0.9575506, 0.1525899],+ [0.9660432, 0.5287710, 0.6654660, 0.3797526, 0.4981400],+ [0.7422802, 0.9926301, 0.5334370, 0.7852844, 0.4397180],+ [0.2281681, 0.2560037, 0.5134379, 0.5800887, 0.8685090]]])++ # OpenCV+ expected = torch.Tensor([[[4.5945477, 4.268469, 0.9738468, 2.2731707, 3.269344],+ [0.6149417, 3.8969188, 2.292972, 3.7777472, 0.9459598],+ [4.003296, 5.4079432, 4.566101, 5.869351, 1.8194631],+ [3.2098956, 4.271444, 0.29820946, 4.7041655, 0.7340856],+ [0.78329855, 2.2872903, 5.3016634, 5.634379, 3.382815]],++ [[0.48054275, 0.51843, 0.44070444, 0.5224365, 0.33946657],+ [0.2985475, 0.18669781, 0.45586777, 0.5633283, 0.5373864],+ [0.6006086, 0.41335985, 0.5978296, 0.45972168, 0.6845894],+ [0.38564888, 0.80442977, 0.6957935, 0.48032972, 0.6066474],+ [0.5889454, 0.53727096, 0.2848544, 0.5161035, 0.7544351]],++ [[0.5255313, 0.79561585, 0.9480225, 0.30024928, 0.59078425],+ [0.98750657, 0.7458223, 0.3854456, 0.90278864, 0.8317882],+ [0.9149786, 0.4157338, 0.16817844, 0.82978433, 0.5911325],+ [0.9247565, 0.9623155, 0.53370523, 0.63488615, 0.4243758],+ [0.8776869, 0.96239233, 0.91754496, 0.55295944, 0.46453667]]])# Korniaf = kornia.color.RgbToHls()data = data.repeat(2, 1, 1, 1) # 2x3x5x5- expected = np.expand_dims(expected, 0)- expected = expected.repeat(2, 0) # 2x3x5x5+ expected = expected.repeat(2, 1, 1, 1) # 2x3x5x5assert_allclose(f(data), expected)def test_nan_rgb_to_hls(self):- data = torch.rand(1, 5, 5) # 3x5x5+ data = torch.ones(1, 5, 5) # 3x5x5data = data.repeat(3, 1, 1) # 2x3x5x5# OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- expected = cv2.cvtColor(data_cv, cv2.COLOR_RGB2HLS)- expected[:, :, 0] = 2 * math.pi * expected[:, :, 0] / 360.-- expected = expected.transpose(2, 0, 1)+ expected = torch.cat([torch.zeros(1, 5, 5), torch.ones(1, 5, 5), torch.zeros(1, 5, 5)], dim=0)# Korniaf = kornia.color.RgbToHls()@@ -110,16 +156,40 @@ class TestHlsToRgb:def test_hls_to_rgb(self):- data = torch.rand(3, 5, 5)+ data = torch.Tensor([[[0.5513626, 0.8487718, 0.1822479, 0.2851745, 0.2669488],+ [0.7596772, 0.4565057, 0.6181599, 0.3852497, 0.7746902],+ [0.5742747, 0.1957062, 0.7530835, 0.2104362, 0.9449323],+ [0.9918052, 0.2437515, 0.4718738, 0.8502576, 0.1675640],+ [0.9210159, 0.0538564, 0.5801026, 0.6110542, 0.3768399]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- data_cv[:, :, 0] = 360 * data_cv[:, :, 0]- expected = cv2.cvtColor(data_cv, cv2.COLOR_HLS2RGB)+ [[0.4111853, 0.0183454, 0.7832276, 0.2975794, 0.1139528],+ [0.6207729, 0.1073406, 0.8335325, 0.5700451, 0.2594557],+ [0.7520493, 0.5097187, 0.4719872, 0.9477938, 0.1640292],+ [0.8973427, 0.6455371, 0.7567374, 0.3159562, 0.8135307],+ [0.0855004, 0.6645504, 0.9923756, 0.6209313, 0.2356791]],++ [[0.4734681, 0.0422099, 0.7405791, 0.9671807, 0.1793800],+ [0.8221875, 0.7219887, 0.3627397, 0.4403201, 0.0024084],+ [0.0803350, 0.9432759, 0.0241543, 0.8292291, 0.7745832],+ [0.3707901, 0.0851424, 0.5805428, 0.1098685, 0.4238486],+ [0.1058410, 0.0816052, 0.5792874, 0.9578886, 0.6281684]]]) # 3x5x5- r_expected = expected[:, :, 0]- g_expected = expected[:, :, 1]- b_expected = expected[:, :, 2]+ # OpenCV+ r_expected = torch.Tensor([[0.21650219, 0.01911971, 0.91374826, 0.1760952, 0.10979544],+ [0.6569808, 0.02984191, 0.77314806, 0.3807273, 0.25964087],+ [0.7321301, 0.8110298, 0.4724091, 0.96834683, 0.2910835],+ [0.935407, 0.6478001, 0.615513, 0.3506698, 0.89171433],+ [0.0945498, 0.6919248, 0.98795897, 0.25782573, 0.08763295]])+ g_expected = torch.Tensor([[0.48587522, 0.017571, 0.9437648, 0.5853925, 0.13439366],+ [0.30897713, 0.18483935, 0.8082967, 0.75936294, 0.25883088],+ [0.7542145, 0.97218925, 0.46058673, 0.9910847, 0.03697497],+ [0.8592784, 0.675717, 0.8979618, 0.28124255, 0.8925654],+ [0.07645091, 0.6548674, 0.99254686, 0.500144, 0.38372523]])+ b_expected = torch.Tensor([[0.60586834, 0.01897625, 0.62269044, 0.00976634, 0.09351197],+ [0.93256867, 0.14439031, 0.89391685, 0.49867177, 0.2600806],+ [0.7719684, 0.04724807, 0.48338777, 0.904503, 0.12093388],+ [0.8630215, 0.6153573, 0.85029656, 0.34361976, 0.73449594],+ [0.08502806, 0.6371759, 0.99679226, 0.9840369, 0.16492467]])# Korniaf = kornia.color.HlsToRgb()@@ -136,14 +206,42 @@ class TestHlsToRgb:def test_batch_hls_to_rgb(self):- data = torch.rand(3, 5, 5) # 3x5x5+ data = torch.Tensor([[[0.5513626, 0.8487718, 0.1822479, 0.2851745, 0.2669488],+ [0.7596772, 0.4565057, 0.6181599, 0.3852497, 0.7746902],+ [0.5742747, 0.1957062, 0.7530835, 0.2104362, 0.9449323],+ [0.9918052, 0.2437515, 0.4718738, 0.8502576, 0.1675640],+ [0.9210159, 0.0538564, 0.5801026, 0.6110542, 0.3768399]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- data_cv[:, :, 0] = 360 * data_cv[:, :, 0]- expected = cv2.cvtColor(data_cv, cv2.COLOR_HLS2RGB)+ [[0.4111853, 0.0183454, 0.7832276, 0.2975794, 0.1139528],+ [0.6207729, 0.1073406, 0.8335325, 0.5700451, 0.2594557],+ [0.7520493, 0.5097187, 0.4719872, 0.9477938, 0.1640292],+ [0.8973427, 0.6455371, 0.7567374, 0.3159562, 0.8135307],+ [0.0855004, 0.6645504, 0.9923756, 0.6209313, 0.2356791]],++ [[0.4734681, 0.0422099, 0.7405791, 0.9671807, 0.1793800],+ [0.8221875, 0.7219887, 0.3627397, 0.4403201, 0.0024084],+ [0.0803350, 0.9432759, 0.0241543, 0.8292291, 0.7745832],+ [0.3707901, 0.0851424, 0.5805428, 0.1098685, 0.4238486],+ [0.1058410, 0.0816052, 0.5792874, 0.9578886, 0.6281684]]]) # 3x5x5- expected = expected.transpose(2, 0, 1)+ # OpenCV+ expected = torch.Tensor([[[0.21650219, 0.01911971, 0.91374826, 0.1760952, 0.10979544],+ [0.6569808, 0.02984191, 0.77314806, 0.3807273, 0.25964087],+ [0.7321301, 0.8110298, 0.4724091, 0.96834683, 0.2910835],+ [0.935407, 0.6478001, 0.615513, 0.3506698, 0.89171433],+ [0.0945498, 0.6919248, 0.98795897, 0.25782573, 0.08763295]],++ [[0.48587522, 0.017571, 0.9437648, 0.5853925, 0.13439366],+ [0.30897713, 0.18483935, 0.8082967, 0.75936294, 0.25883088],+ [0.7542145, 0.97218925, 0.46058673, 0.9910847, 0.03697497],+ [0.8592784, 0.675717, 0.8979618, 0.28124255, 0.8925654],+ [0.07645091, 0.6548674, 0.99254686, 0.500144, 0.38372523]],++ [[0.60586834, 0.01897625, 0.62269044, 0.00976634, 0.09351197],+ [0.93256867, 0.14439031, 0.89391685, 0.49867177, 0.2600806],+ [0.7719684, 0.04724807, 0.48338777, 0.904503, 0.12093388],+ [0.8630215, 0.6153573, 0.85029656, 0.34361976, 0.73449594],+ [0.08502806, 0.6371759, 0.99679226, 0.9840369, 0.16492467]]])# Korniaf = kornia.color.HlsToRgb()@@ -151,8 +249,7 @@ class TestHlsToRgb:data[0] = 2 * pi * data[0]data = data.repeat(2, 1, 1, 1) # 2x3x5x5- expected = np.expand_dims(expected, 0)- expected = expected.repeat(2, 0) # 2x3x2x2+ expected = expected.repeat(2, 1, 1, 1) # 2x3x2x2assert_allclose(f(data), expected)diff --git a/test/color/test_hsv.py b/test/color/test_hsv.pyindex 714c516b8..904d91000 100644--- a/test/color/test_hsv.py+++ b/test/color/test_hsv.py@@ -5,8 +5,6 @@ import kornia.testing as utils # test utilsfrom test.common import device_typefrom kornia.geometry import pi-import cv2-import numpy as npimport mathimport torch@@ -18,15 +16,40 @@ class TestRgbToHsv:def test_rgb_to_hsv(self):- data = torch.rand(3, 5, 5)+ data = torch.Tensor([[[0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],+ [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],+ [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],+ [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],+ [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- expected = cv2.cvtColor(data_cv, cv2.COLOR_RGB2HSV)+ [[0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],+ [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],+ [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],+ [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],+ [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426]],++ [[0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],+ [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],+ [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],+ [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],+ [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532]]])- h_expected = 2 * math.pi * expected[:, :, 0] / 360.- s_expected = expected[:, :, 1]- v_expected = expected[:, :, 2]+ # OpenCV+ h_expected = torch.Tensor([[1.6519808, 1.3188975, 2.2487938, 3.582216, 2.250954],+ [4.28164, 0.04868213, 0.83454597, 5.533617, 4.319574],+ [3.4185164, 2.7919037, 2.8883224, 1.7474692, 1.3619272],+ [3.6837196, 0.6378961, 5.7213116, 5.2614374, 6.259687],+ [2.929221, 2.5614352, 0.97840965, 1.5729411, 6.0235224]])+ s_expected = torch.Tensor([[0.46999356, 0.52820253, 0.8132473, 0.65267974, 0.899411],+ [0.9497089, 0.534381, 0.48878422, 0.60298723, 0.9163612],+ [0.6343409, 0.87112963, 0.8101612, 0.9500878, 0.8192622],+ [0.99010557, 0.9023306, 0.42042294, 0.8292772, 0.81847864],+ [0.6755719, 0.8493871, 0.93686795, 0.73741645, 0.40461043]])+ v_expected = torch.Tensor([[0.5414237, 0.99627006, 0.89471555, 0.81350225, 0.9483274],+ [0.930656, 0.80207086, 0.8933256, 0.9170977, 0.75575125],+ [0.74157417, 0.86247796, 0.41260356, 0.76009345, 0.7279997],+ [0.86927235, 0.8288748, 0.9647092, 0.892202, 0.7614344],+ [0.8932794, 0.8517839, 0.7621747, 0.8983801, 0.99185926]])# Korniaf = kornia.color.RgbToHsv()@@ -42,22 +65,48 @@ class TestRgbToHsv:def test_batch_rgb_to_hls(self):- data = torch.rand(3, 5, 5) # 3x5x5+ data = torch.Tensor([[[0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],+ [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],+ [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],+ [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],+ [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- expected = cv2.cvtColor(data_cv, cv2.COLOR_RGB2HSV)+ [[0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],+ [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],+ [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],+ [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],+ [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426]],- expected[:, :, 0] = 2 * math.pi * expected[:, :, 0] / 360.- expected = expected.transpose(2, 0, 1)+ [[0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],+ [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],+ [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],+ [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],+ [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532]]])++ # OpenCV+ expected = torch.Tensor([[[1.6519808, 1.3188975, 2.2487938, 3.582216, 2.250954],+ [4.28164, 0.04868213, 0.83454597, 5.533617, 4.319574],+ [3.4185164, 2.7919037, 2.8883224, 1.7474692, 1.3619272],+ [3.6837196, 0.6378961, 5.7213116, 5.2614374, 6.259687],+ [2.929221, 2.5614352, 0.97840965, 1.5729411, 6.0235224]],++ [[0.46999356, 0.52820253, 0.8132473, 0.65267974, 0.899411],+ [0.9497089, 0.534381, 0.48878422, 0.60298723, 0.9163612],+ [0.6343409, 0.87112963, 0.8101612, 0.9500878, 0.8192622],+ [0.99010557, 0.9023306, 0.42042294, 0.8292772, 0.81847864],+ [0.6755719, 0.8493871, 0.93686795, 0.73741645, 0.40461043]],++ [[0.5414237, 0.99627006, 0.89471555, 0.81350225, 0.9483274],+ [0.930656, 0.80207086, 0.8933256, 0.9170977, 0.75575125],+ [0.74157417, 0.86247796, 0.41260356, 0.76009345, 0.7279997],+ [0.86927235, 0.8288748, 0.9647092, 0.892202, 0.7614344],+ [0.8932794, 0.8517839, 0.7621747, 0.8983801, 0.99185926]]])# Korniaf = kornia.color.RgbToHsv()data = data.repeat(2, 1, 1, 1) # 2x3x5x5-- expected = np.expand_dims(expected, 0)- expected = expected.repeat(2, 0) # 2x3x5x5+ expected = expected.repeat(2, 1, 1, 1) # 2x3x5x5assert_allclose(f(data), expected)@@ -67,11 +116,8 @@ class TestRgbToHsv:data = data.repeat(3, 1, 1) # 2x3x5x5# OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- expected = cv2.cvtColor(data_cv, cv2.COLOR_RGB2HSV)- expected[:, :, 0] = 2 * math.pi * expected[:, :, 0] / 360.-- expected = expected.transpose(2, 0, 1)+ expected = torch.zeros(1, 5, 5) # 3x5x5+ expected = expected.repeat(3, 1, 1) # 2x3x5x5# Korniaf = kornia.color.RgbToHsv()@@ -111,20 +157,43 @@ class TestHsvToRgb:def test_hsv_to_rgb(self):- data = torch.rand(3, 5, 5) # 3x5x5+ data = torch.Tensor([[[3.5433271, 5.6390061, 1.3766849, 2.5384088, 4.6848912],+ [5.7209363, 5.3262630, 6.2059994, 4.1164689, 2.3872600],+ [0.6370091, 3.6186798, 5.9170871, 2.8275447, 5.4289737],+ [0.2751994, 1.6632686, 1.0049511, 0.7046204, 1.3791083],+ [0.7863123, 4.4852505, 4.3064494, 2.5573561, 5.9083076]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- data_cv[:, :, 0] = 360 * data_cv[:, :, 0]- expected = cv2.cvtColor(data_cv, cv2.COLOR_HSV2RGB)+ [[0.5026655, 0.9453601, 0.5929778, 0.2632897, 0.4590443],+ [0.6201433, 0.5610679, 0.9653260, 0.0830478, 0.5000827],+ [0.6067343, 0.6422323, 0.6777940, 0.7705711, 0.6050767],+ [0.5495264, 0.5573426, 0.4683768, 0.2268902, 0.2116482],+ [0.6525245, 0.0022379, 0.4909980, 0.1682271, 0.6327152]],++ [[0.8471680, 0.9302199, 0.3265766, 0.7944570, 0.7038843],+ [0.4833369, 0.2088473, 0.1169234, 0.4966302, 0.6448684],+ [0.2713015, 0.5893380, 0.6015301, 0.6801558, 0.2322258],+ [0.5704236, 0.6797268, 0.4755683, 0.4811209, 0.5317836],+ [0.3236262, 0.0999796, 0.3614958, 0.5117705, 0.8194097]]]) # 3x5x5- r_expected = expected[:, :, 0]- g_expected = expected[:, :, 1]- b_expected = expected[:, :, 2]+ # OpenCV+ r_expected = torch.Tensor([[0.4213259, 0.93021995, 0.26564622, 0.58528465, 0.5338429],+ [0.48333693, 0.20884734, 0.11692339, 0.45538613, 0.32238087],+ [0.2713015, 0.2108461, 0.60153013, 0.15604737, 0.23222584],+ [0.5704236, 0.4568531, 0.4755683, 0.48112088, 0.49611038],+ [0.32362622, 0.09981924, 0.20394461, 0.42567685, 0.81940967]])+ g_expected = torch.Tensor([[0.6838029, 0.0508271, 0.3265766, 0.794457, 0.3807702],+ [0.18359877, 0.0916698, 0.00405421, 0.45823452, 0.6448684],+ [0.20682439, 0.41690278, 0.1938166, 0.68015575, 0.0917114],+ [0.33933756, 0.6797268, 0.4665822, 0.44541004, 0.5317836],+ [0.27101707, 0.09975589, 0.18400209, 0.51177055, 0.30095676]])+ b_expected = torch.Tensor([[0.84716797, 0.5917818, 0.13292392, 0.6739741, 0.7038843],+ [0.34453064, 0.19874583, 0.01237347, 0.4966302, 0.41256943],+ [0.10669357, 0.589338, 0.3363524, 0.5229789, 0.20633064],+ [0.25696078, 0.30088606, 0.25282317, 0.37195927, 0.41923255],+ [0.11245217, 0.09997964, 0.3614958, 0.46373847, 0.4865534]])# Korniaf = kornia.color.HsvToRgb()- data[0] = 2 * pi * data[0]result = f(data)r = result[0, :, :]@@ -137,23 +206,48 @@ class TestHsvToRgb:def test_batch_hsv_to_rgb(self):- data = torch.rand(3, 5, 5) # 3x5x5+ data = torch.Tensor([[[3.5433271, 5.6390061, 1.3766849, 2.5384088, 4.6848912],+ [5.7209363, 5.3262630, 6.2059994, 4.1164689, 2.3872600],+ [0.6370091, 3.6186798, 5.9170871, 2.8275447, 5.4289737],+ [0.2751994, 1.6632686, 1.0049511, 0.7046204, 1.3791083],+ [0.7863123, 4.4852505, 4.3064494, 2.5573561, 5.9083076]],- # OpenCV- data_cv = data.numpy().transpose(1, 2, 0).copy()- data_cv[:, :, 0] = 360 * data_cv[:, :, 0]- expected = cv2.cvtColor(data_cv, cv2.COLOR_HSV2RGB)+ [[0.5026655, 0.9453601, 0.5929778, 0.2632897, 0.4590443],+ [0.6201433, 0.5610679, 0.9653260, 0.0830478, 0.5000827],+ [0.6067343, 0.6422323, 0.6777940, 0.7705711, 0.6050767],+ [0.5495264, 0.5573426, 0.4683768, 0.2268902, 0.2116482],+ [0.6525245, 0.0022379, 0.4909980, 0.1682271, 0.6327152]],++ [[0.8471680, 0.9302199, 0.3265766, 0.7944570, 0.7038843],+ [0.4833369, 0.2088473, 0.1169234, 0.4966302, 0.6448684],+ [0.2713015, 0.5893380, 0.6015301, 0.6801558, 0.2322258],+ [0.5704236, 0.6797268, 0.4755683, 0.4811209, 0.5317836],+ [0.3236262, 0.0999796, 0.3614958, 0.5117705, 0.8194097]]]) # 3x5x5- expected = expected.transpose(2, 0, 1)+ # OpenCV+ expected = torch.Tensor([[[0.4213259, 0.93021995, 0.26564622, 0.58528465, 0.5338429],+ [0.48333693, 0.20884734, 0.11692339, 0.45538613, 0.32238087],+ [0.2713015, 0.2108461, 0.60153013, 0.15604737, 0.23222584],+ [0.5704236, 0.4568531, 0.4755683, 0.48112088, 0.49611038],+ [0.32362622, 0.09981924, 0.20394461, 0.42567685, 0.81940967]],++ [[0.6838029, 0.0508271, 0.3265766, 0.794457, 0.3807702],+ [0.18359877, 0.0916698, 0.00405421, 0.45823452, 0.6448684],+ [0.20682439, 0.41690278, 0.1938166, 0.68015575, 0.0917114],+ [0.33933756, 0.6797268, 0.4665822, 0.44541004, 0.5317836],+ [0.27101707, 0.09975589, 0.18400209, 0.51177055, 0.30095676]],++ [[0.84716797, 0.5917818, 0.13292392, 0.6739741, 0.7038843],+ [0.34453064, 0.19874583, 0.01237347, 0.4966302, 0.41256943],+ [0.10669357, 0.589338, 0.3363524, 0.5229789, 0.20633064],+ [0.25696078, 0.30088606, 0.25282317, 0.37195927, 0.41923255],+ [0.11245217, 0.09997964, 0.3614958, 0.46373847, 0.4865534]]])# Korniaf = kornia.color.HsvToRgb()- data[0] = 2 * pi * data[0]data = data.repeat(2, 1, 1, 1) # 2x3x5x5-- expected = np.expand_dims(expected, 0)- expected = expected.repeat(2, 0) # 2x3x5x5+ expected = expected.repeat(2, 1, 1, 1) # 2x3x5x5assert_allclose(f(data), expected)