Video-Gen / modules /lut.py
Jacky2305's picture
Create modules/lut.py
716249d verified
Raw
History Blame
1.65 kB
import numpy as np
LUTS = {
"cinematic": {
"name": "🎬 甡影橙青",
"matrix": np.array([[1.1, 0.0, -0.1], [0.0, 1.05, 0.0], [-0.05, 0.0, 1.15]]),
"warmth": (5, 0, -5), "contrast": 1.15,
},
"bw": {
"name": "⬛ 经典黑白",
"matrix": np.array([[0.3, 0.59, 0.11], [0.3, 0.59, 0.11], [0.3, 0.59, 0.11]]),
"warmth": (0, 0, 0), "contrast": 1.3,
},
"cyberpunk": {
"name": "πŸŒ† θ΅›εšζœ‹ε…‹",
"matrix": np.array([[0.8, 0.0, 0.3], [0.0, 0.9, 0.1], [0.1, 0.0, 1.3]]),
"warmth": (-10, 0, 15), "contrast": 1.2,
},
"warm": {
"name": "β˜€οΈ ζ—₯η³»ζš–ι˜³",
"matrix": np.array([[1.1, 0.05, 0.0], [0.0, 1.0, -0.05], [-0.05, -0.05, 0.9]]),
"warmth": (15, 5, -10), "contrast": 0.95,
},
"noir": {
"name": "πŸŒ™ ε€œζ™―θ“θ°ƒ",
"matrix": np.array([[0.7, 0.0, 0.2], [0.0, 0.8, 0.1], [0.1, 0.0, 1.2]]),
"warmth": (-15, -5, 10), "contrast": 1.25,
},
}
def apply_lut(frame, lut_name):
lut = LUTS.get(lut_name)
if not lut:
return frame
frame_float = frame.astype(np.float32)
h, w = frame.shape[:2]
pixels = frame_float.reshape(-1, 3)
transformed = pixels @ lut["matrix"].T
transformed = np.clip(transformed, 0, 255).reshape(h, w, 3)
b, g, r = cv2.split(transformed.astype(np.uint8))
r = cv2.add(r, lut["warmth"][0])
g = cv2.add(g, lut["warmth"][1])
b = cv2.add(b, lut["warmth"][2])
frame = cv2.merge([b, g, r])
frame = frame.astype(np.float32)
frame = (frame - 128) * lut["contrast"] + 128
return np.clip(frame, 0, 255).astype(np.uint8)