Skip to content

Commit

Permalink
Hue sat adjustments work, selection doesn't yet
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfreilich committed May 2, 2024
1 parent 3475fff commit cc07882
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ def do_hue_sat(self, image, hue_low, hue_low_feather, hue_high, hue_high_feather
image_hsv[..., 1] = adjust_saturation(image_hsv[..., 1], sat_offset)

# Adjust lightness
lightness_adjust = lightness_offset / 100.0 * (-1 if lightness_offset < 0 else (1 - image_hsv[..., 2]))
image_hsv[..., 2] = torch.clamp(image_hsv[..., 2] + lightness_adjust, 0, 1)
image_hsv = adjust_lightness(image_hsv, lightness_offset)

# Convert back to RGB
adjusted_image_rgb = hsv_to_rgb(image_hsv[..., :3])
Expand Down Expand Up @@ -591,4 +590,19 @@ def adjust_hue(hue, hue_offset):
hue_offset_normalized = hue_offset / 360.0
# Apply the normalized hue_offset and ensure the result is within [0, 1]
new_hue = (hue + hue_offset_normalized) % 1.0
return new_hue
return new_hue

def adjust_lightness(image_hsv, lightness_offset):
# Map lightness_offset to [-1, 1]
offset = lightness_offset / 100.0

# If lightness_offset < 0, interpolate between the image and a black image
if lightness_offset < 0:
image_hsv[..., 2] = image_hsv[..., 2] * (1 + offset)
# If lightness_offset > 0, interpolate between the image and a white image
elif lightness_offset > 0:
image_hsv[..., 2] = image_hsv[..., 2] * (1 - offset) + offset
# Also reduce the saturation as the lightness increases
image_hsv[..., 1] = image_hsv[..., 1] * ((1 - offset) ** 0.45)

return image_hsv

0 comments on commit cc07882

Please sign in to comment.