Unverified Commit ab73b448 authored by Kushajveer Singh's avatar Kushajveer Singh Committed by GitHub
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
parent 5f4b5794
import unittest
import random
import colorsys
import math
from PIL import Image
from PIL.Image import NEAREST, BILINEAR, BICUBIC
......@@ -114,7 +115,13 @@ class Tester(unittest.TestCase):
colorsys_img = torch.tensor(hsv, dtype=torch.float32)
max_diff = (colorsys_img - ft_hsv_img).abs().max()
ft_hsv_img_h, ft_hsv_img_sv = torch.split(ft_hsv_img, [1, 2], dim=1)
colorsys_img_h, colorsys_img_sv = torch.split(colorsys_img, [1, 2], dim=1)
max_diff_h = ((colorsys_img_h * 2 * math.pi).sin() - (ft_hsv_img_h * 2 * math.pi).sin()).abs().max()
max_diff_sv = (colorsys_img_sv - ft_hsv_img_sv).abs().max()
max_diff = max(max_diff_h, max_diff_sv)
self.assertLess(max_diff, 1e-5)
def test_adjustments(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment