Skip to content

Commit e91c6e2

Browse files
committed
merge brightness contrast and hue adjustment together
1 parent 2b7a99e commit e91c6e2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

test/test_transforms_v2.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6207,10 +6207,8 @@ def test_correctness_image(self, make_input, hue_factor):
62076207
actual = F.adjust_hue(image, hue_factor=hue_factor)
62086208

62096209
if make_input is make_image_cvcuda:
6210-
actual = F.cvcuda_to_tensor(actual).to(device="cpu")
6211-
actual = actual.squeeze(0)
6212-
image = F.cvcuda_to_tensor(image)
6213-
image = image.squeeze(0)
6210+
actual = cvcuda_to_pil_compatible_tensor(actual)
6211+
image = cvcuda_to_pil_compatible_tensor(image)
62146212

62156213
expected = F.to_image(F.adjust_hue(F.to_pil_image(image), hue_factor=hue_factor))
62166214

torchvision/transforms/v2/functional/_color.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,12 @@ def _adjust_hue_cvcuda(image: "cvcuda.Tensor", hue_factor: float) -> "cvcuda.Ten
471471
return image
472472

473473
# no native adjust_hue, use CV-CUDA for color converison, use torch for elementwise operations
474+
# CV-CUDA accelerates the HSV conversion
474475
hsv = cvcuda.cvtcolor(image, cvcuda.ColorConversion.RGB2HSV)
476+
# then use torch for elementwise operations
475477
hsv_torch = torch.as_tensor(hsv.cuda()).float()
476478
hsv_torch[..., 0] = (hsv_torch[..., 0] + hue_factor * 180) % 180
479+
# convert back to cvcuda tensor and accelerate the HSV2RGB conversion
477480
hsv_modified = cvcuda.as_tensor(hsv_torch.to(torch.uint8), "NHWC")
478481
return cvcuda.cvtcolor(hsv_modified, cvcuda.ColorConversion.HSV2RGB)
479482

0 commit comments

Comments
 (0)