Add gamma

This commit is contained in:
Andras Schmelczer 2024-06-18 22:55:07 +01:00
parent 388d3d3ce3
commit 8277768df8
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 70 additions and 0 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,12 @@
import numpy as np
from random import choice
from PIL import Image
def adjust_gamma(img: Image, gamma: float) -> Image:
return img.point(lambda x: (x / 255) ** gamma * 255)
def get_random_gamma() -> float:
gamma = np.random.beta(1, 2) * 0.6
return 1 / (1 + gamma) if choice([True, False]) else (gamma + 1)