View Full Version : Brightness filter without altering blacks and whites?
mpxman
8th July 2016, 19:12
I'm lookin Avisynth brightness filter that works like brightness adjustment in some image editing softwares that increase brightness but does on affect pure blacks and whites.
I have tried gamma correction but it adds too much brightness to dark shades.
I think I would be happy with this kind of adjustment. You could increase and decrease brightness by moving that black point along the blue line.
http://i.imgur.com/G5CRZ1P.png
Should work in range of 16 - 235 and optionally 0 - 255, YUY2 and YV12.
feisty2
8th July 2016, 19:22
Smoothadjust
mpxman
8th July 2016, 20:19
Smoothadjust
If I understood right this will do the job?
BRIGHTNESS = 20
PARAMETERS = "0-0;" + String(128-BRIGHTNESS, "%0.0f") + "-" + String(128+BRIGHTNESS, "%0.0f") + ";" + "255-255"
SmoothCurve(clip, Ycurve=PARAMETERS, TVrange=1)
SmoothAdjust http://forum.doom9.org/showthread.php?t=154971
Is there any simpler way?
Edit:
I'm using the script above with SmoothAdjust. I add some saturation to compensate the color loss.
raffriff42
8th July 2016, 20:32
SGradation is easier to use, but does not dither like Smoothadjust. Should be OK if you don't need a radical adjustment.
http://avisynth.nl/index.php/SGradation
kuchikirukia
8th July 2016, 21:04
Stainless' RGB Adapt can do that if you convert to RGB. It even comes with a tool for those curves.
http://forum.doom9.org/showthread.php?t=170642
I don't know if his ColorYUV can do something similar. I've never used it.
http://forum.doom9.org/showthread.php?t=156774
mpxman
8th July 2016, 21:06
If I understood right this will do the job?
BRIGHTNESS = 20
PARAMETERS = "0-0;" + String(128-BRIGHTNESS, "%0.0f") + "-" + String(128+BRIGHTNESS, "%0.0f") + ";" + "255-255"
SmoothCurve(clip, Ycurve=PARAMETERS, TVrange=1)
Is there any simpler way?
That did not work well. I compared that curves in Photoshop and SmoothCurve loses colors and add noise (this was my mistake).
http://i.imgur.com/4WQA7ef.png
http://i.imgur.com/XpsA4db.png
Edit:
Noise difference was an error because denoising was mistakenly on. Only differense is loss of colors.
johnmeyer
8th July 2016, 21:09
I've posted this same advice in many other threads, but I suggest you'd be better off doing this in a competent NLE. Any adjustments to luma levels should be done using a histogram, calibrated monitor, and interactive tools which instantly let you see the results of each and every adjustment. I use Sony Vegas which has a histogram adjustment tool called "Color Curves." It actually has nothing directly to do with color, although you can independently adjust each color channel, if you wish. Here is what it looks like:
http://i177.photobucket.com/albums/w208/johnmeyer/ColorCurves.jpg
In this example I am boosting the lower midtones. You can add as many adjustment points as you like, and can control, using the Bezier handles, the shape of the curve. Minor adjustments can make a huge difference in outcome which is why an interactive tool is, IMHO, mandatory.
Motenai Yoda
8th July 2016, 21:14
with X darker < 1.0 < brighter
levels(0,X,255,0,255,coring=true)
with dither package there is a dither argument to enable dithering
also with coring false it works on 0-255 range
or
X = 1.0
mt_lut("x 16 235 clip 16 - 219. / 1 "+string(X)+" / ^ 219. * 16 +",u=2,v=2)
GMJCZP
8th July 2016, 21:31
Try with YLevels_mt by Didée.
mpxman
8th July 2016, 22:02
with X darker < 1.0 < brighter
levels(0,X,255,0,255,coring=true)
with dither package there is a dither argument to enable dithering
also with coring false it works on 0-255 range
or
X = 1.0
mt_lut("x 16 235 clip 16 - 219. / 1 "+string(X)+" / ^ 219. * 16 +",u=2,v=2)
Levels is used for gamma. It boosts too much dark shades. I don't know what later code do.
Motenai Yoda
8th July 2016, 22:41
with coring = true it works exactly as you want (it will map 16-235 to 0-255 and back), moving that point of the curve up and down is the same as gamma correction.
the later code do exactly the same
it don't increase saturation coz you're working in a yuv (or what you want calling it) colorspace and the gamma stuff is done only on the luma (Y) channel, while photoshop works in an RGB colorspace.
StainlessS
8th July 2016, 23:06
Here RGBAdapt, http://forum.doom9.org/showthread.php?t=170642
ColorYUV2, http://forum.doom9.org/showthread.php?t=156774&highlight=Coloryuv2
mpxman
8th July 2016, 23:10
with coring = true it works exactly as you want (it will map 16-235 to 0-255 and back), moving that point of the curve up and down is the same as gamma correction.
the later code do exactly the same
it don't increase saturation coz you're working in a yuv (or what you want calling it) colorspace and the gamma stuff is done only on the luma (Y) channel, while photoshop works in an RGB colorspace.
I have used levels(0,X,255,0,255,coring=true). Thas was in my script but was not satisfied with it. Gamma curve (black line in picture) boosts dark shades much more than curves tool in Photoshop or in Paint Shop Pro. The red line, with smoothing, is what I'm looking for.
http://i.imgur.com/mWQrqR0.gif
I tested again SmoothCurve and used Histogram("levels"). Historam shows that Y channels is changed but there is also little changes in U and V channels. Is that a bug in SmoothCurve?
raffriff42
9th July 2016, 01:07
I was wrong about SGradation not dithering - it does so by wrapping SmoothAdjust.
Here are some tests. You should be able to get what you want with one of these.
https://www.dropbox.com/s/t9zictc62o72ech/gamma31-Levels%20cor%3DT.png?raw=1
https://www.dropbox.com/s/9m1kkzpekuirf86/gamma32-SGrad-1.png?raw=1
https://www.dropbox.com/s/329nspdc2gco4h8/gamma34-Sgrad%2BLevels-2.png?raw=1
https://www.dropbox.com/s/imxg79rcdgho4rp/gamma35-Levels%20cor%3DF-2.png?raw=1
LoadPlugin(p+ "SmoothAdjust\SmoothAdjust-3,20\x86\SmoothAdjust.dll")
Import(p + "SGradation.avsi")
ColorBarsHD
Crop(162, 482, -162, -180) ## get the grayscale ramp
BilinearResize(680, Height) ## size for forum post
O=Last
<filter under test>
StackVertical(Last, O.Crop(0, 0, 0, 16)) ## add reference line
TurnRight.Histogram.TurnLeft ## rotated Histogram
Subtitle(<caption>, align=7)
vcmohan
9th July 2016, 12:16
In my plugin HistogramAdjust one can specify a desired Histogram. It works on Y plane of planar formats.
mpxman
9th July 2016, 14:26
Thanks for averybody. This wasn't as easy as I though. As johnmeyer said NLE would be handy.
I tested SmoothCurve again. I created YV16 video clip that coverted to RGB in VirtualDub gives RGB(128, 65,127), HueSatLight(212, 83, 97).
I used SmoothCurve(Ycurve="0-0;108-148;255-255", TVrange=1). I got RGB(167, 102, 168), HueSatLight(211, 70, 135).
With same points "0-0;108-148;255-255" Photoshop gives RGB(169, 95, 168), HueSatLight(212, 77, 132).
Saturation is decreased in SmoothCurve much more than in PhotoShop. There is no preserve saturation option.
mpxman
9th July 2016, 19:32
Photoshop uses cubic splines for curve interpolation (http://blog.ivank.net/interpolation-with-cubic-splines.html ).
http://i.imgur.com/vCojjzD.png
I plotted flipped gamma function y=1-(1-x)^gamma. It's quite similar but more agressive on white shades.
http://i.imgur.com/ruVLAsI.png
poisondeathray
9th July 2016, 19:58
Did you only want to affect Y curve?
If you don't mind working in RGB, you try try gradation curves in Vdub , it's going to be most similar to photoshop curves with a GUI. But I don't recall if you can load it with LoadVirtualDubPlugin in avisynth.
But Gimp curves or Photoshop amp file with GiCoCu can be loaded in avisynth
http://avisynth.org.ru/docs/english/externalfilters/gicocu.htm
There is also free version of davinci resolve, the free version has a few limitations but probably more than you need
mpxman
10th July 2016, 15:15
Did you only want to affect Y curve?
If you don't mind working in RGB, you try try gradation curves in Vdub , it's going to be most similar to photoshop curves with a GUI. But I don't recall if you can load it with LoadVirtualDubPlugin in avisynth.
But Gimp curves or Photoshop amp file with GiCoCu can be loaded in avisynth
http://avisynth.org.ru/docs/english/externalfilters/gicocu.htm
There is also free version of davinci resolve, the free version has a few limitations but probably more than you need
I would like to work on YUV. I use SmoothCurve and try to compesate the loss of saturation by using tweak(). I just needed a one parameter brightness that is gentle on max whites and blacks.
I have stabilizer, descratch, dirt removing, denoising, resizing and sharpening in my Avisynth script. I would need those in NLE. My old films are short but my Avisynth script is painfully slow, about 1 fps. Corresponding tools in NLE might be much much faster but also expensive.
Motenai Yoda
10th July 2016, 15:28
what about
x^(1/1.6) + (0.4 * x * (1/1-x))
mpxman
11th July 2016, 16:39
what about
x^(1/1.6) + (0.4 * x * (1/1-x))
I did not fully understood that equation but I tried to write similar equation.
g = "gamma"
a = 0.3 = constant that modifies the curve
y = x^(1 + (1/g - 1)*(x + a) )
http://i.imgur.com/frWCdIe.png
How can I write that equation and the flipped gamma function y=1-(1-x)^g so that those work with mt_lut?
StainlessS
11th July 2016, 20:27
Easiest way to do that with no overhead worth considering is to use Mt_Polish() to convert to reverse Polish notation.
So it is a matter of concatenating variable arguments as string into infix notation, and then convert to reverse Polish.
The very definitely easiest way that I'm aware of is to use RT_string() from RT_Stats (maybe I'm a bit biased there).
eg
g=2.0 # EDIT: Added
Infix1 = RT_String("1-(1-x)^%f",g) # %f, insertion marker for Float arg g (insertion markers correspond to arg order)
# %d, = int
# %s, = string
# EDIT: '%%' is escaped, if '%' is required in output string.
You could insert an infix string into another one, for more complex result, eg
Some_float_arg=0.54321
Infix2 = RT_String("(%s)*%f",Infix1,Some_float_arg)
# We encompass the string insertion marker with () ie "(%s)" just to avoid unhappy mistakes (operator precedence).
# We could have enclosed in parenthesis at the Infix1 step ie used:- Infix1 = RT_String("(1-(1-x)^%f)",g)
Polish = Mt_Polish(Infix2)
Infix3 = Mt_Infix(Polish)
Colorbars.KillAudio.RT_Subtitle("""Infix1 = %s\nInfix2 = %s\nPolish = %s\nInfix3 = %s""",Infix1,Infix2,Polish,Infix3)
# The \n insert Newlines or Chr(10), next line down.
Totally untested.
EDIT: Infix3 should be mathematically same to Infix2, or else problem somewhere.
And Polish is string used in Mt_Lut().
EDIT: Below TESTED,
g=2.0
Infix1 = RT_String("1-(1-x)^%f",g)
Some_float_arg=0.54321
Infix2 = RT_String("(%s)*%f",Infix1,Some_float_arg)
Polish = Mt_Polish(Infix2)
Infix3 = Mt_Infix(Polish)
RT_DebugF("""Infix1 = %s\nInfix2 = %s\nPolish = %s\nInfix3 = %s""",Infix1,Infix2,Polish,Infix3,name="MPXMAN: ")
Colorbars.KillAudio.RT_Subtitle("""Infix1 = %s\nInfix2 = %s\nPolish = %s\nInfix3 = %s""",Infix1,Infix2,Polish,Infix3)
Writes this to DebugView
00000010 20:24:37.796 MPXMAN: Infix1 = 1-(1-x)^2.000000
00000011 20:24:37.796 MPXMAN: Infix2 = (1-(1-x)^2.000000)*0.543210
00000012 20:24:37.796 MPXMAN: Polish = 1 1 x - 2.000000 ^ - 0.543210 *
00000013 20:24:37.796 MPXMAN: Infix3 = ((1-((1-x)^2.000000))*0.543210)
Which looks about right to me.
Above is not intended to be your solution, only how to do it [Teach a Man To Fish, and You Feed Him for a Lifetime, etc].
Motenai Yoda
11th July 2016, 21:55
I did not fully understood that equation but I tried to write similar equation.
It's a gamma and a gain which decrease with x
to write in polish notation write the first term then the second term and the operator
ie
a + b => a b +
x^(1/1.6) + (0.4 * x * (1-x))
x 1 1.6 / ^ x .4 * 1 x - * +
but as you're working in a 0-255 range and you want 16-235 limits you have to replace x with x 16 - 219 /
x 16 - 219 / 1 1.6 / ^ x 16 - 219 / .4 * 1 x - * +
and still it needs to avoit over-range values, so replace again x with x 16 235 clip
x 16 235 clip 16 - 219 / 1 1.6 / ^ x 16 235 clip 16 - 219 / .4 * 1 x - * +
to use a variable to set the strength there are 2 simply ways
use it to multiply the gamma and gain values, or to the whole thing (maybe better)
ie
bright = .5 # from 0.0 to 1.0
"x 16 235 clip 16 - 219 / 1 1 .6 "+string(bright)+" * + / ^ x 16 235 clip 16 - 219 / .4 "+string(bright)+" * * 1 x - * +"
"x 16 235 clip 16 - 219 / 1 1.6 / ^ x 16 235 clip 16 - 219 / .4 * 1 x - * + "+string(bright)+" * x 1 "+string(bright)+" - * +"
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.