Reduce colors
Reduce or manipulate colors
To reduce or manipulate colors you can work in RGB or HSV color space.
More details how to set the the color of an pixel. Write to fragment output
Reduce colors
(ns lv.demo)
(use 'lv.core)
(layout "grid" [img0 img1]
[img2 img3])
; assume there are 4 PNG images in the media folder.
(image "flower-sampler/*.png")
(render)
; Do not modify the image.
; Copies red green and blue without modification from image c0.
(rgb :img0 [c0 c1 c2 c3]
(rgb c2.rgb)
)
; work with hsv color space
; transform a rgb color into its corresponding gray scale
; weight the contribution of each channel separately.
(hsv :img1 [c0 c1 c2 c3]
(v (+ (* 0.299 c2.r)
(* 0.587 c2.g)
(* 0.114 c2.b)))
)
; work with hsv color space
; use value / brightness from hsv color model
; and add an vignette effect.
; r is the distance from the center.
(hsv :img2 [c0 c1 c2 c3]
(v (* 1.5 (- 1 r) c2.v))
)
; work with rgb color space
; reduce each rgb channel to only 2 steps.
(rgb :img3 [c0 c1 c2 c3]
(rgb (/ (floor (* 2 c2.rgb)) 2))
)
Manipulate colors by combining different images
(ns lv.demo)
(use 'lv.core)
(layout "grid" [img0 img1]
[img2 img3])
; assume there are 4 PNG images in the media folder.
(image "flower-sampler/*.png")
(render)
; multiply hsv channels of two images
(hsv :img0 [c0 c1 c2 c3]
(hsv (* c0.hsv c2.hsv))
)
; mix hsv channels of two images
; use the value of a third image as weight fro mixing.
(hsv :img1 [c0 c1 c2 c3]
(hsv (mix c0.hsv c2.hsv c1.v))
)
; mix one hsv channel with some constant values
; use the value of an additional image as weight factor for mixing.
(hsv :img2 [c0 c1 c2 c3]
(hsv (mix c0.hsv
(vec3 0.795 0.354 0.181)
c1.v))
)
; add rgb values of 4 input images
; every image has its own weight
; Use cosine function to invert and remap to 0.0 .. 1.0 range
(rgb :img3 [c0 c1 c2 c3]
(rgb (cos (+ (* 0.740 c0.rgb)
(* 0.622 c1.rgb)
(* 0.535 c2.rgb)
(* 0.425 c3.rgb))))
)