Initial commit: video effects processing system
Add S-expression based video effects pipeline with modular effect definitions, constructs, and recipe files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
63
effects/sharpen.py
Normal file
63
effects/sharpen.py
Normal file
@@ -0,0 +1,63 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = ["numpy", "opencv-python"]
|
||||
# ///
|
||||
"""
|
||||
@effect sharpen
|
||||
@version 1.0.0
|
||||
@author artdag
|
||||
|
||||
@description
|
||||
Sharpening effect using unsharp mask technique. Enhances edges and detail.
|
||||
Great for making footage pop on beats.
|
||||
|
||||
@param amount float
|
||||
@range 0 5
|
||||
@default 1.0
|
||||
Sharpening intensity. 0 = no change, 1 = normal, 2+ = aggressive.
|
||||
|
||||
@param radius float
|
||||
@range 0 10
|
||||
@default 1
|
||||
Radius of sharpening (affects edge thickness).
|
||||
|
||||
@example
|
||||
(effect sharpen :amount 1.5)
|
||||
|
||||
@example
|
||||
;; Sharpen on beats
|
||||
(effect sharpen :amount (bind bass :range [0.5 2.0]))
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
def process_frame(frame: np.ndarray, params: dict, state: dict) -> tuple:
|
||||
"""
|
||||
Apply sharpening to a video frame.
|
||||
|
||||
Args:
|
||||
frame: Input frame as numpy array (H, W, 3) RGB uint8
|
||||
params: Effect parameters
|
||||
- amount: sharpening intensity (default 1.0)
|
||||
- radius: edge radius (default 1)
|
||||
state: Persistent state dict (unused)
|
||||
|
||||
Returns:
|
||||
Tuple of (processed_frame, new_state)
|
||||
"""
|
||||
amount = params.get("amount", 1.0)
|
||||
radius = params.get("radius", 1)
|
||||
|
||||
if amount <= 0:
|
||||
return frame, state
|
||||
|
||||
# Create blurred version
|
||||
ksize = max(1, int(radius)) * 2 + 1
|
||||
blurred = cv2.GaussianBlur(frame, (ksize, ksize), 0)
|
||||
|
||||
# Unsharp mask: original + amount * (original - blurred)
|
||||
result = frame.astype(np.float32) + amount * (frame.astype(np.float32) - blurred.astype(np.float32))
|
||||
|
||||
return np.clip(result, 0, 255).astype(np.uint8), state
|
||||
Reference in New Issue
Block a user