Motenai Yoda
7th June 2015, 16:54
Hi, folks!
I'm trying to get an HSL like Chroma sharpen that sharps independently a "Luma related" saturation plane, and an Hue plane, using its sine and cosine...
dependencies should be avs 2.6, masktools2 and ditherpackage
function HSL_ChromaSharp(clip c, int "radius", bool "preblur", bool "lsb_out")
{
lsb_out = Default(lsb_out, False)
Blur = Default(radius, 1)
PreBlur = Default(preblur, True)
function HSL_Sharp_Blur(clip c, int radius, int y, int u, int v)
{
rgY = (y==3) ? 20 : (y==2) ? 0 : -1
rgU = (u==3) ? 20 : (u==2) ? 0 : -1
rgV = (v==3) ? 20 : (v==2) ? 0 : -1
box_radius = max(radius, 2)
(box_radius == 1) ? c.Dither_removegrain16(rgY, rgU, rgV) : c.Dither_box_filter16(radius=box_radius, y=y, u=v, v=u)
}
#Chroma = uv distance from 0,0 (128,128)
Chroma = Dither_lutxy8(c.utoy(), c.vtoy(), "x 128 - 112. / 2 ^ y 128 - 112. / 2 ^ + .5 ^ 255. * 256. *", u=1, v=1).converttoy8()
Luma = Spline36resize(c.converttoy8(), c.width()/2, c.height()/2)
#Saturation relative to luma = Chroma [0,255] / Luma [16,235] -> [1,255] avoiding division per 0 when Luma <= 16
Saturation_MSB = Dither_lutxy8(Chroma.Dither_get_msb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + / 256. *")
Saturation_LSB = Dither_lutxy8(Chroma.Dither_get_lsb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + /*")
Saturation = Dither_add16(Saturation_MSB, Saturation_LSB, y=3, u=1, v=1)
#Hue = Cosine (u) and Sine (v) of the angle, simply divide by Chroma * sqrt(2)
Hue =Dither_lutxy8(c, ytouv(Chroma.ditherpost(), Chroma.ditherpost(), c), "y 0 == x 128 - x 128 - abs / x 128 - 112. / y 255. / / ? 128. * 2 .5 ^ / 128 + 256. *", y=1, u=3, v=3)
#Hue =Dither_lutxy8(c, ytouv(Chroma.dither_get_msb(), Chroma.dither_get_msb(), c), "y 0 == x 128 - x 128 - abs / x 128 - 112. / y 255. / / ? 128. * 2 .5 ^ / 128 + 256. *", y=1, u=3, v=3)
Sat_Pre = (PreBlur) ? Saturation.HSL_Sharp_Blur(Blur, 3, 1, 1) : Saturation
Hue_Pre = (PreBlur) ? Hue.HSL_Sharp_Blur(Blur, 1, 3, 3) : Hue
Sat_Blurred = Sat_Pre.HSL_Sharp_Blur(Blur, 3, 1, 1)
Hue_Blurred = Hue_Pre.HSL_Sharp_Blur(Blur, 1, 3, 3)
Sat_Sharped = Saturation.Dither_add16(Sat_Pre.Dither_sub16(Sat_Blurred, dif=true), dif=true)
Hue_Sharped = Hue.Dither_add16(Hue_Pre.Dither_sub16(Hue_Blurred, y=1, u=3, v=3, dif=true), y=1, u=3, v=3, dif=true)
#Sat_Sharped [0,255] * Luma [16,255] -> [1,255]
Chroma_New_MSB = Dither_lutxy8(Sat_Sharped.Dither_get_msb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + * 256. *")
Chroma_New_LSB = Dither_lutxy8(Sat_Sharped.Dither_get_lsb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + *")
Chroma_New = Dither_add16(Chroma_New_MSB, Chroma_New_LSB, y=3, u=1, v=1).ditherpost()
#getting back UV planes,
Hue_New_MSB = Dither_lutxy8(Hue_Sharped.Dither_get_msb(), ytouv(Chroma_New,Chroma_New,c), "x 128 - 128. / y 255. / * 112. * 2 .5 ^ * 128 + 256. *", y=1, u=3, v=3)
Hue_New_LSB = Dither_lutxy8(Hue_Sharped.Dither_get_lsb(), ytouv(Chroma_New,Chroma_New,c), "x 128 - 128. / y 255. / * 112. * 2 .5 ^ *", y=1, u=3, v=3)
Hue_New = Dither_add16(Hue_New_MSB, Hue_New_LSB, y=1, u=3, v=3)
(lsb_out) ? c.Dither_convert_8_to_16().MergeChroma(Hue_New) : c.MergeChroma(Hue_New.ditherpost())
}
any comment or suggestion are welcome
I'm trying to get an HSL like Chroma sharpen that sharps independently a "Luma related" saturation plane, and an Hue plane, using its sine and cosine...
dependencies should be avs 2.6, masktools2 and ditherpackage
function HSL_ChromaSharp(clip c, int "radius", bool "preblur", bool "lsb_out")
{
lsb_out = Default(lsb_out, False)
Blur = Default(radius, 1)
PreBlur = Default(preblur, True)
function HSL_Sharp_Blur(clip c, int radius, int y, int u, int v)
{
rgY = (y==3) ? 20 : (y==2) ? 0 : -1
rgU = (u==3) ? 20 : (u==2) ? 0 : -1
rgV = (v==3) ? 20 : (v==2) ? 0 : -1
box_radius = max(radius, 2)
(box_radius == 1) ? c.Dither_removegrain16(rgY, rgU, rgV) : c.Dither_box_filter16(radius=box_radius, y=y, u=v, v=u)
}
#Chroma = uv distance from 0,0 (128,128)
Chroma = Dither_lutxy8(c.utoy(), c.vtoy(), "x 128 - 112. / 2 ^ y 128 - 112. / 2 ^ + .5 ^ 255. * 256. *", u=1, v=1).converttoy8()
Luma = Spline36resize(c.converttoy8(), c.width()/2, c.height()/2)
#Saturation relative to luma = Chroma [0,255] / Luma [16,235] -> [1,255] avoiding division per 0 when Luma <= 16
Saturation_MSB = Dither_lutxy8(Chroma.Dither_get_msb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + / 256. *")
Saturation_LSB = Dither_lutxy8(Chroma.Dither_get_lsb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + /*")
Saturation = Dither_add16(Saturation_MSB, Saturation_LSB, y=3, u=1, v=1)
#Hue = Cosine (u) and Sine (v) of the angle, simply divide by Chroma * sqrt(2)
Hue =Dither_lutxy8(c, ytouv(Chroma.ditherpost(), Chroma.ditherpost(), c), "y 0 == x 128 - x 128 - abs / x 128 - 112. / y 255. / / ? 128. * 2 .5 ^ / 128 + 256. *", y=1, u=3, v=3)
#Hue =Dither_lutxy8(c, ytouv(Chroma.dither_get_msb(), Chroma.dither_get_msb(), c), "y 0 == x 128 - x 128 - abs / x 128 - 112. / y 255. / / ? 128. * 2 .5 ^ / 128 + 256. *", y=1, u=3, v=3)
Sat_Pre = (PreBlur) ? Saturation.HSL_Sharp_Blur(Blur, 3, 1, 1) : Saturation
Hue_Pre = (PreBlur) ? Hue.HSL_Sharp_Blur(Blur, 1, 3, 3) : Hue
Sat_Blurred = Sat_Pre.HSL_Sharp_Blur(Blur, 3, 1, 1)
Hue_Blurred = Hue_Pre.HSL_Sharp_Blur(Blur, 1, 3, 3)
Sat_Sharped = Saturation.Dither_add16(Sat_Pre.Dither_sub16(Sat_Blurred, dif=true), dif=true)
Hue_Sharped = Hue.Dither_add16(Hue_Pre.Dither_sub16(Hue_Blurred, y=1, u=3, v=3, dif=true), y=1, u=3, v=3, dif=true)
#Sat_Sharped [0,255] * Luma [16,255] -> [1,255]
Chroma_New_MSB = Dither_lutxy8(Sat_Sharped.Dither_get_msb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + * 256. *")
Chroma_New_LSB = Dither_lutxy8(Sat_Sharped.Dither_get_lsb(), Luma, "x y 16 235 clip 16 - 219. / 254. * 1 + *")
Chroma_New = Dither_add16(Chroma_New_MSB, Chroma_New_LSB, y=3, u=1, v=1).ditherpost()
#getting back UV planes,
Hue_New_MSB = Dither_lutxy8(Hue_Sharped.Dither_get_msb(), ytouv(Chroma_New,Chroma_New,c), "x 128 - 128. / y 255. / * 112. * 2 .5 ^ * 128 + 256. *", y=1, u=3, v=3)
Hue_New_LSB = Dither_lutxy8(Hue_Sharped.Dither_get_lsb(), ytouv(Chroma_New,Chroma_New,c), "x 128 - 128. / y 255. / * 112. * 2 .5 ^ *", y=1, u=3, v=3)
Hue_New = Dither_add16(Hue_New_MSB, Hue_New_LSB, y=1, u=3, v=3)
(lsb_out) ? c.Dither_convert_8_to_16().MergeChroma(Hue_New) : c.MergeChroma(Hue_New.ditherpost())
}
any comment or suggestion are welcome