View Full Version : color balance only on the bright parts?
zee944
27th December 2008, 15:17
EDIT: The question below isn't important anymore. Please look at post #15 (http://forum.doom9.org/showthread.php?p=1243769#post1243769)
How can I adjust color balance on only the bright parts of an image?
I thought ColorBalance (http://forum.doom9.org/showthread.php?t=139361) will do this for me, but what ColorBalance calls "Highlights" are still too dark to me. I really want to touch only the very bright (almost-white) parts.
How can it be done with masks? I'm thinking about adjusting RGB with RGBAdjust on the whole image, then mask it over the original image with adjustable threshold. But as always, I'm just assuming that's the right way, I don't have the ability to do that. Can anyone help?
Thanks for any inputs. :)
thetoof
27th December 2008, 15:33
You can create a mask using a lut:
#Ajust the threshold to determine which pixels to select. Possible values are from 0 (all pixels) to 255 (only brightest)
source=file
colorbalanced=file.filters
threshold=xxx
mask=source.mt_lut("x "+string(threshold)+" > 255 0 ?",u=0,v=0)
mt_merge(source,colorbalanced,mask,u=3,v=3)
#return mask #uncomment this line to see the mask
zee944
27th December 2008, 16:51
Thanks, this is close what I want... except one thing. There's no fine transition between the two layers. How can be some fade in / fade out trick done to make it smooth?
LoadPlugin("E:\mt_masktools[2.0a30].dll")
source=MPEG2Source("Twin_Dragons_Metropolitan_VideoFile.d2v")
colorbalanced=source.ColorYUV(gain_y=132,cont_y=32,cont_u=64)
threshold=128
mask=source.mt_lut("x "+string(threshold)+" > 255 0 ?",u=0,v=0)
mt_merge(source,colorbalanced,mask,u=3,v=3)
#return mask #uncomment this line to see the mask
rfmmars
27th December 2008, 17:47
Also you can use "Fdump's" RGBeq 2.11 Virtualdub plugin to do both hue and chroma control/balance for any part of the video lum. range.
Richard
photorecall.net
IanB
27th December 2008, 23:22
Blur the resulting mask or define the mask to have an edge range instead of a hard threshold.
i.e.
...
T1=124
T2=132
Mask=Source.Levels(T1, 1.0, T2, 0, 255, False)
...
AVIL
28th December 2008, 14:30
To smooth a binary mask you can try DistanceFunction from AVSInpaint plugin, created by AMSS0815:
DistanceFunction computes the distance function around or inside a given set of pixels. E.g. it can create a frame, where each pixels value is the distance of the respective pixel to a given set of pixels. This is typically used to inflate or deflate masks, or to create masks with smooth borders out of binary masks.
You can get it at:
http://forum.doom9.org/showthread.php?t=133682&highlight=avsinpaint
zee944
31st December 2008, 18:52
Thank you for all of you.
Meanwhile I realized what I've originally asked for would only be a short term solution for my problem. How can I create a mask containing an arbitrary fade in/fade out part of certain luma segments?
For instance, what if I'd like to create the following mask:
- every pixels from the original image which had the luma value between 90 and 180 (so filtering out every pixel below 90 and over 180)
- every pixels which had the luma value between 40 and 90, but with increasing luma on the mask (40 -> 0% of original brightness, 41 -> 2%, [...] 90 -> 100% brightness)
- every pixels which had the luma value between 180 and 230, but with decreasing luma on the mask (180 -> 100% of original brightness, 179 -> 98%, [...] 230 -> 0% brightness)
I know it's slightly more complicated, but if someone could do this for me, I could probably do the "opposite" of this mask (the very bright and very dark parts), and any kind of these masks. Then I could set the color balance of the separated masks differently and blend them together again smoothly.
I hope it'll only be a finger exercise for an expert... :) Can someone do this? :D
IanB
31st December 2008, 23:11
...lut("x 180 < x 40 - 255 * 50 / 180 x - 255 * 50 / 255 + ?")
If (X < 180) {
X = (X - 40)*255/50
} Else {
X = 255 + (180 - X)*255/50
}
# Implicit coring by lut functions
If (X < 0) X = 0
If (X > 255) X = 255
LaTo
1st January 2009, 10:19
Into a function:
function Tmask ( clip clp, int "thr1", int "thr2", int "thr3", int "thr4", bool "reverse" ) {
mt_lut(clp.greyscale(),expr="x "+string(thr2)+" "+string(thr3)+" + 2 / < x "+string(thr1)+" - 255 * "+string(thr2)+" "+string(thr1)+" - / "
\ +string(thr3)+" x - 255 * "+string(thr4)+" "+string(thr3)+" - / 255 + ?",U=2,V=2)
return reverse?last.invert():last }
Tmask(thr1=40,thr2=90,thr3=180,thr4=230,reverse=false)
:)
zee944
1st January 2009, 15:45
Oops, probably my wording was poor. These codes don't do what I wanted :D
I'd like to have a color mask. Between luma 90..230, the original pixels with their original R, G, B values on the mask. Between 40..90 ("fading in") and 180..230 ("fading out"), the adjusted luma version of the original pixels, with altered R, G, B levels to have their luma values between 0..90 and 180..0. Like this:
original luma ............ output luma
0 ...................................... 0
1 ...................................... 0
2 ...................................... 0
[...]
38 ..................................... 0
39 ..................................... 0
40 ..................................... 0
41 ..................................... 1.8
42 ..................................... 3.6
[...]
88 ..................................... 86.4
89 ..................................... 88.2
90 ..................................... 90
91 ..................................... 91
92 ..................................... 92
[...]
178 ..................................... 178
179 ..................................... 179
180 ..................................... 180
181 ..................................... 178.2
182 ..................................... 176.4
[...]
228 ..................................... 3.6
229 ..................................... 1.8
230 ..................................... 0
231 ..................................... 0
232 ..................................... 0
[...]
253 ..................................... 0
254 ..................................... 0
255 ..................................... 0
I hope I made it clear this time. Perhaps I shouldn't use the expression "mask". I don't know if it's a mask at all.
And one more thing, could you do the three things (fade in, fade out, simple "copiing") totally seperatedly? It'd be much easier to understand and use. (I want to create custom masks later, for instance "fade out" from 0 to 128, zero pixels from 128 to 200, then "fade in" from 200 to 255 etc.)
LaTo
1st January 2009, 16:19
I don't understand, sorry :confused:
Try Tmask like this:
src=last
fix=src.tweak(sat=2)
mask=src.Tmask(thr1=40,thr2=90,thr3=180,thr4=230,reverse=true)
mt_merge(src,fix,mask,luma=true,chroma="process")
Delete tweak(sat=2) and replace with your own filter (also set reverse=false/true)...
zee944
1st January 2009, 18:44
I don't understand, sorry :confused:
I don't understand anymore either... probably my approach was wrong. Instead of masking, it'd need Tweak(), SmoothLevels() or something similar. Simply I have to darken 0-40 to zero, decrease darkening between 40-90, keep the image intact between 90-180, and so on... Take my tabling (second column) as desired luma values within the image after some tweaking. Do you see now what I want to achieve?
LaTo
2nd January 2009, 08:17
I don't understand anymore either... probably my approach was wrong. Instead of masking, it'd need Tweak(), SmoothLevels() or something similar. Simply I have to darken 0-40 to zero, decrease darkening between 40-90, keep the image intact between 90-180, and so on... Take my tabling (second column) as desired luma values within the image after some tweaking. Do you see now what I want to achieve?
Strange, but if you really want to do this, try:
mt_lutxy(last,last.Tmask(thr1=40,thr2=90,thr3=180,thr4=230,reverse=false),"x y * 255 /", chroma="copy first")
zee944
2nd January 2009, 12:17
Strange, but if you really want to do this, try:
mt_lutxy(last,last.Tmask(thr1=40,thr2=90,thr3=180,thr4=230,reverse=false),"x y * 255 /", chroma="copy first")
Yes, that's what I want! Thanks :)
Could you do the three things (fade in, fade out, copiing pixels) seperatedly, in stand-alone lines? I'm trying to understand the expression format from the MaskTools documentation, but it's way beyond me.
zee944
30th January 2009, 18:38
Thanks for the help to LaTo so far.
--
Could someone modify the following script for me to do the three or four things in separatedly?
(Between luma values 40..90 it does some sort of fading in; between 0..40 and 230..255 it simply makes the pixels black; between 180..230 some sort of fading out, between 90..180 it does nothing. It is perhaps a bit clearer in post #10 (http://forum.doom9.org/showthread.php?p=1230637#post1230637).)
function Tmask ( clip clp, bool "reverse" ) {
mt_lut(clp,expr="x 90 180 + 2 / < x 40 - 255 * 90 40 - / 180 x - 255 * 230 180 - / 255 + ?",U=2,V=2)
return reverse?last.invert():last }
MPEG2Source("Twin_Dragons_Metropolitan_VideoFile.d2v")
mt_lutxy(last,last.Tmask(reverse=false),"x y * 255 /", chroma="copy first")
I assume this "x 90 180 + 2 / < x 40 - 255 * 90 40 - / 180 x - 255 * 230 180 - / 255 + ?" expression should be simplified, which at the moment does perfectly all I need above - but all in one, and I can't figure out how to separate each steps.
Pretty please. :)
LaTo
30th January 2009, 18:54
In order:
"x 40 <= 0 x ?"
"x 40 > x 90 < & x 40 - 255 * 50 / x ?"
"x 90 >= x 180 <= & 255 x ?"
"x 180 > x 230 < & 255 180 x - 255 * 50 / + x ?"
"x 230 >= 0 x ?"
zee944
1st February 2009, 15:04
Thank you LaTo!
I'm playing around with the expressions and it seems I've started understanding this "reverse polish notation" thing... I hope I didn't speak it too soon :D Thank you for the help. :)
In order:
"x 40 <= 0 x ?"
"x 40 > x 90 < & x 40 - 255 * 50 / x ?"
"x 90 >= x 180 <= & 255 x ?"
"x 180 > x 230 < & 255 180 x - 255 * 50 / + x ?"
"x 230 >= 0 x ?"
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.