Add editing methods
This commit is contained in:
commit
f7d9c0193d
12 changed files with 161 additions and 0 deletions
3
editor/operations/__init__.py
Normal file
3
editor/operations/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from .add_noise import add_noise
|
||||
from .change_temperature import change_temperature
|
||||
from .add_random_colour_spill import add_random_colour_spill
|
||||
11
editor/operations/add_noise.py
Normal file
11
editor/operations/add_noise.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def add_noise(img: Image, alpha: float) -> Image:
|
||||
img = img.convert("RGB")
|
||||
width, height = img.size
|
||||
random_colors = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
|
||||
random_img = Image.fromarray(random_colors, mode="RGB")
|
||||
result = Image.blend(img, random_img, alpha)
|
||||
return result
|
||||
20
editor/operations/add_random_colour_spill.py
Normal file
20
editor/operations/add_random_colour_spill.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from PIL import Image
|
||||
from ..utils import random
|
||||
|
||||
|
||||
def add_random_colour_spill(image: Image, range: float) -> Image:
|
||||
matrix = (
|
||||
random(1 / range, range),
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
random(1 / range, range),
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
random(1 / range, range),
|
||||
0.0,
|
||||
)
|
||||
return image.convert("RGB", matrix)
|
||||
42
editor/operations/change_temperature.py
Normal file
42
editor/operations/change_temperature.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from PIL import Image
|
||||
|
||||
kelvin_table = {
|
||||
1000: (255, 56, 0),
|
||||
1500: (255, 109, 0),
|
||||
2000: (255, 137, 18),
|
||||
2500: (255, 161, 72),
|
||||
3000: (255, 180, 107),
|
||||
3500: (255, 196, 137),
|
||||
4000: (255, 209, 163),
|
||||
4500: (255, 219, 186),
|
||||
5000: (255, 228, 206),
|
||||
5500: (255, 236, 224),
|
||||
6000: (255, 243, 239),
|
||||
6500: (255, 249, 253),
|
||||
7000: (245, 243, 255),
|
||||
7500: (235, 238, 255),
|
||||
8000: (227, 233, 255),
|
||||
8500: (220, 229, 255),
|
||||
9000: (214, 225, 255),
|
||||
9500: (208, 222, 255),
|
||||
10000: (204, 219, 255),
|
||||
}
|
||||
|
||||
|
||||
def change_temperature(image: Image, temperature: float) -> Image:
|
||||
r, g, b = kelvin_table[temperature]
|
||||
matrix = (
|
||||
r / 255.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
g / 255.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
b / 255.0,
|
||||
0.0,
|
||||
)
|
||||
return image.convert("RGB", matrix)
|
||||
Loading…
Add table
Add a link
Reference in a new issue