SGradation
From Avisynth wiki
(Difference between revisions)
m (1 revision) |
Raffriff42 (Talk | contribs) (added SGradation2, SGradation2S) |
||
| Line 26: | Line 26: | ||
# similar to the well known gamma. Values below 1.0 reduce contrast. | # similar to the well known gamma. Values below 1.0 reduce contrast. | ||
# | # | ||
| − | |||
| − | |||
# | # | ||
| − | # float | + | # float gammaB, gammaW |
# allow separate gamma values for the dark/light part of the image. | # allow separate gamma values for the dark/light part of the image. | ||
# | # | ||
| Line 60: | Line 58: | ||
# | # | ||
function SGradation(clip clp, val "gamma") { | function SGradation(clip clp, val "gamma") { | ||
| − | + | g=Float(Default(gamma, 1.0)) | |
| − | + | gc=clp.GreyScale() #.ColorYUV(levels="TV->PC") | |
| − | + | dk=gc.Levels(0,1.0/g,127,0,127) | |
| − | + | lt=gc.Levels(235,1.0/g,128,107,0,coring=false) | |
| − | # dk=gc.Levels(127,g,0,127,0) | + | # dk=gc.Levels(127,g,0,127,0) |
| − | # lt=gc.Levels(128,g,235,0,107,coring=false) | + | # lt=gc.Levels(128,g,235,0,107,coring=false) |
| − | + | r=Overlay(dk,lt,mode="add") | |
| − | + | r.MergeChroma(clp) #.ColorYUV(levels="PC->TV") | |
} | } | ||
| − | + | ||
| + | ## independent control of highlights & lowlights | ||
| + | # | ||
| + | function SGradation2(clip clp, val "gammaW", val "gammaB") | ||
| + | { | ||
| + | gW = Float(Default(gammaW, 1.0)) | ||
| + | gB = Float(Default(gammaB, 1.0)) | ||
| + | |||
| + | gc = clp.GreyScale() | ||
| + | |||
| + | dk = gc.Levels( 0, 1.0/gB, 127, 0, 127) | ||
| + | lt = gc.Levels(235, 1.0/gW, 128, 107, 0, coring=false) | ||
| + | |||
| + | r = Overlay(dk, lt, mode="add") | ||
| + | r.MergeChroma(clp) | ||
| + | } | ||
| + | |||
| + | ## independent control of highlights & lowlights with debanding | ||
| + | ## http://forum.doom9.org/showthread.php?p=1637727#post1637727 | ||
| + | ## requires SmoothAdjust | ||
| + | ## http://forum.doom9.org/showthread.php?t=154971 | ||
| + | # | ||
| + | function SGradation2S(clip clp, val "gammaW", val "gammaB") | ||
| + | { | ||
| + | gW = Float(Default(gammaW, 1.0)) | ||
| + | gB = Float(Default(gammaB, 1.0)) | ||
| + | |||
| + | gc = clp.GreyScale() | ||
| + | |||
| + | dk = gc.SmoothLevels( 16, 1.0/gB, 127, 16, 127, smooth=200, limiter=1) | ||
| + | lt = gc.SmoothLevels(235, 1.0/gW, 128, 107, 0, smooth=200) | ||
| + | |||
| + | r = Overlay(dk, lt, mode="add") | ||
| + | r.MergeChroma(clp) | ||
| + | } | ||
| + | |||
Back to [[Shared functions]]. | Back to [[Shared functions]]. | ||
[[Category:Shared_functions]] | [[Category:Shared_functions]] | ||
[[Category:External filters]] | [[Category:External filters]] | ||
Latest revision as of 19:29, 24 August 2013
#
# SGradation() is a "2nd order gamma" function.
#
# While overall luma and contrast, i.e. levels 0, 128, 255, are not affected,
# SGradation expands or compresses the luma histogram outwards from he center
# (with gamma > 1.0) or towards the center (with gamma < 1.0).
#
# SGradation() allows to soften the visual contrast of images with too much
# contrast. But rather than just reducing all the contrast, SGradation()
# leaves black, medium lightness and white untouched, and just reduces the
# lightness of very light, respectively increases the lightness of dark areas.
# This is useful after recapturing movies if the camera could not cover the
# projection contrast.
#
# On the other hand, the effective contrast of dim pictures can be expanded,
# yet conserving the details in dark and light areas, i.e. not saturating
# and cutting black and white areas, but leaving a soft gradient.
#
#
# Parameters
#
# clip clp
# must be given and is the modified clip.
#
# float gamma
# similar to the well known gamma. Values below 1.0 reduce contrast.
#
#
# float gammaB, gammaW
# allow separate gamma values for the dark/light part of the image.
#
# bool pclevels
# when true, assumes and returns "PC" luma levels.
# (see ColorYUV doc for explanation)
#
#
# output luma with gamma < 1.0
# ^
# 255+ +
# | +
# | +
# | +
# | +
# | +
# | +
# 128+ +++
# | +
# | +
# | +
# | +
# |+
# |+
# 0+-------------+-------------+> input luma
# 0 128 255
#
#
# 04/16/2007 martin53
#
function SGradation(clip clp, val "gamma") {
g=Float(Default(gamma, 1.0))
gc=clp.GreyScale() #.ColorYUV(levels="TV->PC")
dk=gc.Levels(0,1.0/g,127,0,127)
lt=gc.Levels(235,1.0/g,128,107,0,coring=false)
# dk=gc.Levels(127,g,0,127,0)
# lt=gc.Levels(128,g,235,0,107,coring=false)
r=Overlay(dk,lt,mode="add")
r.MergeChroma(clp) #.ColorYUV(levels="PC->TV")
}
## independent control of highlights & lowlights
#
function SGradation2(clip clp, val "gammaW", val "gammaB")
{
gW = Float(Default(gammaW, 1.0))
gB = Float(Default(gammaB, 1.0))
gc = clp.GreyScale()
dk = gc.Levels( 0, 1.0/gB, 127, 0, 127)
lt = gc.Levels(235, 1.0/gW, 128, 107, 0, coring=false)
r = Overlay(dk, lt, mode="add")
r.MergeChroma(clp)
}
## independent control of highlights & lowlights with debanding
## http://forum.doom9.org/showthread.php?p=1637727#post1637727
## requires SmoothAdjust
## http://forum.doom9.org/showthread.php?t=154971
#
function SGradation2S(clip clp, val "gammaW", val "gammaB")
{
gW = Float(Default(gammaW, 1.0))
gB = Float(Default(gammaB, 1.0))
gc = clp.GreyScale()
dk = gc.SmoothLevels( 16, 1.0/gB, 127, 16, 127, smooth=200, limiter=1)
lt = gc.SmoothLevels(235, 1.0/gW, 128, 107, 0, smooth=200)
r = Overlay(dk, lt, mode="add")
r.MergeChroma(clp)
}
Back to Shared functions.