Log in

View Full Version : Advanced Contrast/Shadow Manipulation


matfra
19th June 2012, 12:42
Hello everyone,
I would like to know if there is some plugins that you can control the Shadow, Mids, High levels. I want a sharpening tool that can enhanced edge and shadow. I used LFSMode, but it seem only to apply shapening to all the image, and no control on specific things.

Didée
19th June 2012, 14:09
Quickly knocked together. Yell if you find bugs, I didn't even try it.

Fuzzyness could be refined, and the thresholds must be strictly ascending (th1 > th2 > th3 > th4), the script doesn't check that.

function Mix3( clip c, clip "dark", clip "medium", clip "bright", int "th1", int "th2", int "th3", int "th4", int "fuzzy", int "Y", int "U", int "V")
{
dark = default( dark, c ) # pre-filtered clip to be used for "dark areas"
medium = default( medium, c ) # pre-filtered clip to be used for "medium areas"
bright = default( bright, c ) # pre-filtered clip to be used for "bright areas"
th1 = default( th1, 24 ) # start of dark->midtone mixing zone
th2 = default( th2, 56 ) # end of dark->midtone mixing zone
th3 = default( th3, 128 ) # start of midtone->bright mixing zone
th4 = default( th4, 160 ) # end of midtone->bright mixing zone
fuzzy = default( fuzzy, 1 ) # whether/how much to soften the clip before taking brightness masks
Y = default( Y, 3 ) # luma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined
U = default( U, 2 ) # U chroma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined
V = default( V, 2 ) # V chroma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined
th1str = string(th1)
th2str = string(th2)
th3str = string(th3)
th4str = string(th4)

c2 = (fuzzy==1) ? c.blur(1)
\ : (fuzzy==2) ? c.blur(1).blur(1.58)
\ : (fuzzy==3) ? c.blur(1).blur(1.58).blur(1.58)
\ : c

chr = (U==3||V==3)
msk1 = c2.mt_lut("x "+th1str+" < 0 x "+th2str+" > 255 255 "+th2str+" "+th1str+" - / x "+th1str+" - * ? ?")
msk2 = c2.mt_lut("x "+th3str+" < 0 x "+th4str+" > 255 255 "+th4str+" "+th3str+" - / x "+th3str+" - * ? ?")

result = dark.mt_merge(medium, msk1, luma=chr, Y=Y,U=U,V=V)
\ .mt_merge(bright, msk2, luma=chr, Y=Y,U=U,V=V)

return(result)
}

matfra
19th June 2012, 14:21
Thank you master Didée. Im gonna try it now.

I get this error in AVSP ?

---------------------------
Error
---------------------------
I don't know what "Y" means
(Mix3.avsi, line 11)
(New File, line 7)
---------------------------
OK
---------------------------



I think the problem is locate in this area

Y = default( Y, 3 ) # luma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined

Guest
19th June 2012, 14:38
If you don't want to pass Y/U/V as parameters and always use the defaults, change these lines:

Y = default( Y, 3 ) # luma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined
U = default( U, 2 ) # U chroma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined
V = default( V, 2 ) # V chroma channel: 3=process, 2=keep unchanged (copy), 1 = random/undefined

to:

Y = 3
U = 2
V = 2

If you want to pass them, then change this line:

function Mix3( clip c, clip "dark", clip "medium", clip "bright", int "th1", int "th2", int "th3", int "th4", int "fuzzy")

to:

function Mix3( clip c, clip "dark", clip "medium", clip "bright", int "th1", int "th2", int "th3", int "th4", int "fuzzy", int "Y", int "U", int "V")

Didée
19th June 2012, 14:58
Oh, yes, I forgot to declare Y+U+V parameters in the function head. Sorry. Corrected. Waiting for more bugs. :D

BTW, mask creation was blind copy+paste from GrainFactory.avs - That should be correct, but you never know.

Gavino
19th June 2012, 16:36
Waiting for more bugs. :D
You forgot to define th1str, etc, eg
th1str = string(th1)

Didée
19th June 2012, 19:39
Hrrrmpf! Yes!

But ... in a sense, I didn't forget to define. I forgot to copy+paste. :rolleyes:

* * *

Meanwhile, I'm at home and actually tried the function. Works now. Hooray! :o:o