Skip to content

Commit ab73b44

Browse files
perform cyclic check for hue in test_rgb2hsv (#2477)
* perform cyclic check for hue in test_rgb2hsv Test fails for cases when hue=0 and hue=360. As hue is cyclic in nature, add cyclic logic for checking the max difference by taking the sin of the tensor and then comparing the max values. * address linter issues
1 parent 5f4b579 commit ab73b44

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/test_functional_tensor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import random
33
import colorsys
4+
import math
45

56
from PIL import Image
67
from PIL.Image import NEAREST, BILINEAR, BICUBIC
@@ -114,7 +115,13 @@ def test_rgb2hsv(self):
114115

115116
colorsys_img = torch.tensor(hsv, dtype=torch.float32)
116117

117-
max_diff = (colorsys_img - ft_hsv_img).abs().max()
118+
ft_hsv_img_h, ft_hsv_img_sv = torch.split(ft_hsv_img, [1, 2], dim=1)
119+
colorsys_img_h, colorsys_img_sv = torch.split(colorsys_img, [1, 2], dim=1)
120+
121+
max_diff_h = ((colorsys_img_h * 2 * math.pi).sin() - (ft_hsv_img_h * 2 * math.pi).sin()).abs().max()
122+
max_diff_sv = (colorsys_img_sv - ft_hsv_img_sv).abs().max()
123+
max_diff = max(max_diff_h, max_diff_sv)
124+
118125
self.assertLess(max_diff, 1e-5)
119126

120127
def test_adjustments(self):

0 commit comments

Comments
 (0)