Import L1 (celery) as l1/
This commit is contained in:
27
l1/sexp_effects/effects/xector_threshold.sexp
Normal file
27
l1/sexp_effects/effects/xector_threshold.sexp
Normal file
@@ -0,0 +1,27 @@
|
||||
;; Threshold effect using xector operations
|
||||
;; Demonstrates where (conditional select) and β (reduction) for normalization
|
||||
|
||||
(require-primitives "xector")
|
||||
|
||||
(define-effect xector_threshold
|
||||
:params (
|
||||
(threshold :type float :default 0.5 :range [0 1] :desc "Brightness threshold (0-1)")
|
||||
(invert :type bool :default false :desc "Invert the threshold")
|
||||
)
|
||||
(let* (
|
||||
;; Get grayscale luminance as xector
|
||||
(luma (gray frame))
|
||||
|
||||
;; Normalize to 0-1 range
|
||||
(luma-norm (α/ luma 255))
|
||||
|
||||
;; Create boolean mask: pixels above threshold
|
||||
(mask (if invert
|
||||
(α< luma-norm threshold)
|
||||
(α>= luma-norm threshold)))
|
||||
|
||||
;; Use where to select: white (255) if above threshold, black (0) if below
|
||||
(out (where mask 255 0)))
|
||||
|
||||
;; Output as grayscale (same value for R, G, B)
|
||||
(rgb out out out)))
|
||||
Reference in New Issue
Block a user