Skip to content

Commit

Permalink
Make adjust_hue() work with numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug committed Jun 3, 2024
1 parent 6e18cea commit 0670bc1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions torchvision/transforms/_functional_pil.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ def adjust_hue(img: Image.Image, hue_factor: float) -> Image.Image:
h, s, v = img.convert("HSV").split()

np_h = np.array(h, dtype=np.uint8)
# uint8 addition take cares of rotation across boundaries
with np.errstate(over="ignore"):
np_h += np.uint8(hue_factor * 255)
shift = int(hue_factor * 255)
if shift > 0:
np_h += shift
else:
np_h -= abs(shift)

h = Image.fromarray(np_h, "L")

img = Image.merge("HSV", (h, s, v)).convert(input_mode)
Expand Down

0 comments on commit 0670bc1

Please sign in to comment.