Move files

This commit is contained in:
Andras Schmelczer 2024-06-18 22:08:48 +01:00
parent 55f5f88687
commit e17068baba
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 97 additions and 98 deletions

View file

@ -1,3 +1,6 @@
from .add_noise import add_noise
from .change_temperature import change_temperature
from .add_random_colour_spill import add_random_colour_spill
from .gamma import adjust_gamma, get_random_gamma
from .get_colour_lut import get_random_saturation_per_hue_lut, get_random_brightness_lut
from .apply_pixel_shader import apply_pixel_shader

View file

@ -0,0 +1,14 @@
from typing import Callable, Tuple
from PIL import Image
def apply_pixel_shader(
img: Image, callback: Callable[[int, int, int], Tuple[int, int, int]]
):
width, height = img.size
pixels = img.load()
for x in range(width):
for y in range(height):
r, g, b = pixels[x, y]
pixels[x, y] = callback(r, g, b)
return img

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,43 @@
import numpy as np
from typing import List
from ..utils.random import random
from .interpolate import interpolate, INTERPOLATION_TYPE
def get_random_saturation_per_hue_lut(
variance: float = 0.4, count: int = 12
) -> List[int]:
edit_points = [random(-variance, variance) + 1 for _ in range(count)]
return [
interpolate(edit_points, i / 255, type="cubic")
for i in np.linspace(0, 255, 256)
]
def get_random_brightness_lut(
variance: float = 0.2,
count: int = 6,
type: INTERPOLATION_TYPE = "linear",
min_spectrum_size: float = 0.6,
max_spectrum_size: float = 1.15,
) -> List[int]:
spectrum_size = np.random.uniform(min_spectrum_size, max_spectrum_size)
spectrum_start = np.random.uniform(0, max(0, 1 - spectrum_size))
edit_points = sorted(
[
spectrum_start,
*[
spectrum_start
+ i * spectrum_size / (count - 2)
+ np.random.uniform(-variance, variance)
for i in range(1, count - 2)
],
spectrum_start + spectrum_size,
]
)
return [
round(interpolate(edit_points, i / 255, type=type) * 255)
for i in np.linspace(0, 255, 256)
]

View file

@ -0,0 +1,33 @@
import numpy as np
from scipy.interpolate import CubicSpline
from typing import List, Literal
INTERPOLATION_TYPE = Literal["cubic", "linear"]
def interpolate(
control_points: List[float], t: float, type: INTERPOLATION_TYPE
) -> float:
if type == "cubic":
x = np.linspace(0, 1, len(control_points))
cs = CubicSpline(x, control_points)
return cs(t)
if type == "linear":
n = len(control_points) - 1
segment_indices = np.linspace(0, 1, n + 1)
index = np.searchsorted(segment_indices, t, side="right") - 1
if t == 1:
return control_points[-1]
else:
t_normalized = (t - segment_indices[index]) / (
segment_indices[index + 1] - segment_indices[index]
)
return control_points[index] + t_normalized * (
control_points[index + 1] - control_points[index]
)
raise ValueError("Invalid type")