jmac698
27th July 2011, 04:35
Hope this didn't exist before :)
This is better I'm sure someone *cough Gavino* will comment :)
#Demo
colorbars(pixel_type="YV12")
yuv2yhs
yhs_viewamp#view saturation, non-solid color indicates slight saturation error (this is not true saturation)
#yhs2yuv
#YHS Tools by jmac v0.3
#Requires Masktools v2 and YV12 video
#Functions to convert to and from YHS which is Y, Hue, Saturation - almost
#Simply finds the phase and amplitude of the YCbCr values
# and scales them back into a YUV clip
#Can be useful to quickly view color hue/saturation. Can also make adjustments to hue/saturation (todo).
#All functions work, reconversion fairly accurate
function yuv2yhs(clip y){
y
dist="x 128 - 2 ^ y 128 - 2 ^ + .5 ^"#sqrt(x^2+y^2)
deg="180 pi / * 360 + 360 %"#(*180/pi+360) % 360
sc1="224 120 / * 16 +"#scale 120 to 16-235 for saturation
sc2="224 360 / * 16 +"#scale 360 degrees to 16-240 to stuff in U
amp=mt_lutxy(utoy,vtoy,dist+" "+sc1)#close to saturation, max=120 (I think)
#check if v is 128, to avoid div0. Return 0 for convenience. Otherwise return atan2(u,v) which is the angle from coord.
#then convert to degress and scale to fit chroma range.
#sample hue's:
#Color Deg Ph Dist Amp
#Blu 351 234 113 175
#Red 109 83 118 181
#Yel 171 122 113 175
#Cyn 289 195 118 181
#ph is close to hue but starting at blue-magenta
ph=mt_lutxy(utoy,vtoy,"y 128 = 0 "+dist+" x 128 - - y 128 - / atan 2 * "+deg+" ? "+sc2)
ytouv(ph,amp,y)
}
function yhs2yuv(clip y){
y
sc1="16 - 120 224 / *"#scale 16-235 to 120 for saturation
sc2="16 - 360 224 / *"#scale 16-240 to 360 degrees
rad="pi 180 / *"#scale degrees to radians
u=mt_lutxy(utoy,vtoy,"x "+sc2+" "+rad+" cos y "+sc1+" * 128 +")
v=mt_lutxy(utoy,vtoy,"x "+sc2+" "+rad+" sin y "+sc1+" * 128 +")
ytouv(u,v,y)
}
function yhs_viewamp(clip y){
vtoy(y)
}
function yhs_viewph(clip y){
utoy(y)
}
function yhs_tweak(clip y, int sat, int hue){
y
#Just mutiply U to increase saturation
#Just add to V to change hue
#todo...
}
This is better I'm sure someone *cough Gavino* will comment :)
#Demo
colorbars(pixel_type="YV12")
yuv2yhs
yhs_viewamp#view saturation, non-solid color indicates slight saturation error (this is not true saturation)
#yhs2yuv
#YHS Tools by jmac v0.3
#Requires Masktools v2 and YV12 video
#Functions to convert to and from YHS which is Y, Hue, Saturation - almost
#Simply finds the phase and amplitude of the YCbCr values
# and scales them back into a YUV clip
#Can be useful to quickly view color hue/saturation. Can also make adjustments to hue/saturation (todo).
#All functions work, reconversion fairly accurate
function yuv2yhs(clip y){
y
dist="x 128 - 2 ^ y 128 - 2 ^ + .5 ^"#sqrt(x^2+y^2)
deg="180 pi / * 360 + 360 %"#(*180/pi+360) % 360
sc1="224 120 / * 16 +"#scale 120 to 16-235 for saturation
sc2="224 360 / * 16 +"#scale 360 degrees to 16-240 to stuff in U
amp=mt_lutxy(utoy,vtoy,dist+" "+sc1)#close to saturation, max=120 (I think)
#check if v is 128, to avoid div0. Return 0 for convenience. Otherwise return atan2(u,v) which is the angle from coord.
#then convert to degress and scale to fit chroma range.
#sample hue's:
#Color Deg Ph Dist Amp
#Blu 351 234 113 175
#Red 109 83 118 181
#Yel 171 122 113 175
#Cyn 289 195 118 181
#ph is close to hue but starting at blue-magenta
ph=mt_lutxy(utoy,vtoy,"y 128 = 0 "+dist+" x 128 - - y 128 - / atan 2 * "+deg+" ? "+sc2)
ytouv(ph,amp,y)
}
function yhs2yuv(clip y){
y
sc1="16 - 120 224 / *"#scale 16-235 to 120 for saturation
sc2="16 - 360 224 / *"#scale 16-240 to 360 degrees
rad="pi 180 / *"#scale degrees to radians
u=mt_lutxy(utoy,vtoy,"x "+sc2+" "+rad+" cos y "+sc1+" * 128 +")
v=mt_lutxy(utoy,vtoy,"x "+sc2+" "+rad+" sin y "+sc1+" * 128 +")
ytouv(u,v,y)
}
function yhs_viewamp(clip y){
vtoy(y)
}
function yhs_viewph(clip y){
utoy(y)
}
function yhs_tweak(clip y, int sat, int hue){
y
#Just mutiply U to increase saturation
#Just add to V to change hue
#todo...
}