Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ternaus committed Nov 19, 2024
1 parent f18e121 commit 71d0d31
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2526,15 +2526,22 @@ def auto_contrast(img: np.ndarray) -> np.ndarray:
# Calculate cumulative distribution
cdf = hist.cumsum()

min_value = cdf.min()
max_value = cdf.max()

if min_value == max_value:
continue

# Normalize CDF
cdf = (cdf - cdf.min()) * max_value / (cdf.max() - cdf.min() + 1e-6)
cdf = (cdf - min_value) * max_value / (max_value - min_value + 1e-6)

# Linear interpolation of CDF to get scaling
scaling_lookup = clip(np.around(cdf), img.dtype)
# Create lookup table
lut = clip(np.around(cdf), np.uint8)

# Apply lookup table
if img.ndim > MONO_CHANNEL_DIMENSIONS:
result[..., i] = scaling_lookup[channel]
result[..., i] = sz_lut(channel, lut)
else:
result = scaling_lookup[channel]
result = sz_lut(channel, lut)

Check warning on line 2545 in albumentations/augmentations/functional.py

View check run for this annotation

Codecov / codecov/patch

albumentations/augmentations/functional.py#L2545

Added line #L2545 was not covered by tests

return result

0 comments on commit 71d0d31

Please sign in to comment.