Move files
This commit is contained in:
parent
55f5f88687
commit
e17068baba
7 changed files with 97 additions and 98 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,6 @@
|
||||||
from .add_noise import add_noise
|
from .add_noise import add_noise
|
||||||
from .change_temperature import change_temperature
|
from .change_temperature import change_temperature
|
||||||
from .add_random_colour_spill import add_random_colour_spill
|
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
|
||||||
|
|
|
||||||
14
src/editor/operations/apply_pixel_shader.py
Normal file
14
src/editor/operations/apply_pixel_shader.py
Normal 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
|
||||||
93
src/editor/operations/get_colour_lut.ipynb
Normal file
93
src/editor/operations/get_colour_lut.ipynb
Normal file
File diff suppressed because one or more lines are too long
43
src/editor/operations/get_colour_lut.py
Normal file
43
src/editor/operations/get_colour_lut.py
Normal 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)
|
||||||
|
]
|
||||||
33
src/editor/operations/interpolate.py
Normal file
33
src/editor/operations/interpolate.py
Normal 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")
|
||||||
|
|
@ -1,10 +1,4 @@
|
||||||
from .interpolate import interpolate
|
|
||||||
from .random import random
|
from .random import random
|
||||||
from .apply_pixel_shader import apply_pixel_shader
|
|
||||||
from .get_colour_lut import (
|
|
||||||
get_random_brightness_lut,
|
|
||||||
get_random_saturation_per_hue_lut,
|
|
||||||
)
|
|
||||||
from .compute_histogram import compute_histogram
|
from .compute_histogram import compute_histogram
|
||||||
from .generate_rotation_matrices import generate_rotation_matrices
|
from .generate_rotation_matrices import generate_rotation_matrices
|
||||||
from .get_next_run_name import get_next_run_name
|
from .get_next_run_name import get_next_run_name
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue