Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th November 2014, 19:28   #1  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
Color temperature change

Exists a plugin or a script, which could change the color temperature?
I've got a TV, where isn't enough of settings. On the screen are faces and grass too yellow, and sky is rather gray than blue.
If I add blue, then sky is OK, but faces are violet, and grass is rather blue than green.
When I add green, then the colors of faces and sky are worse yet.
When I add red, then grass is still the more yellow and sky is violet.
Stormborec is offline   Reply With Quote
Old 26th November 2014, 19:50   #2  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
I'm playing with colorYUV and ColorMill (in RGB), but the results aren't satisfactory (like I wrote before).
Stormborec is offline   Reply With Quote
Old 26th November 2014, 22:42   #3  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
I wrote a script that does a fair job - "CheapColorTemp"
http://forum.doom9.org/showthread.php?t=170309

To emulate color temp shift, you normally adjust offset_mid only,
using offset_lo to to correct the black balance if needed,
and offset_hi to to correct the white balance.

(MaskTools is required)

Code:
#######################################
### emulate color temperature changes in three luma ranges
##
## @ offset_x - arbitrary units; <0 means lower temp (warmer colors)
##     (range -50 to +25; default 0)
##
function CheapColorTemp(clip C, 
\            int offset_lo, int offset_mid, int offset_hi)
{
    Assert(IsClip(C) && C.IsYUV, "CheapColorTemp: source must be YUV")
    offset_lo  = Min(Max(-50, offset_lo),  25)
    offset_mid = Min(Max(-50, offset_mid), 25)
    offset_hi  = Min(Max(-50, offset_hi),  25)

    return C.ColorYUVx3(
    \          off_u_lo =offset_lo,  off_v_lo =Round(-0.7*offset_lo),
    \          off_u_mid=offset_mid, off_v_mid=Round(-0.7*offset_mid),
    \          off_u_hi =offset_hi,  off_v_hi =Round(-0.7*offset_hi))
}

#######################################
### apply ColorYUV U & V offsets to three luma ranges
##
## @ cont_x, off_x - see ColorYUV
## @ showmasks     - if true, show original + 3 masks in quad split
##
function ColorYUVx3(clip C,
\           float "off_u_lo",  float "off_u_mid",  float "off_u_hi",   
\           float "off_v_lo",  float "off_v_mid",  float "off_v_hi",
\           bool "showmasks")
{
    off_u_lo   = Float(Default(off_u_lo,   0.0))
    off_u_mid  = Float(Default(off_u_mid,  0.0))
    off_u_hi   = Float(Default(off_u_hi,   0.0))
    off_v_lo   = Float(Default(off_v_lo,   0.0))
    off_v_mid  = Float(Default(off_v_mid,  0.0))
    off_v_hi   = Float(Default(off_v_hi,   0.0))

    showmasks  = Default(showmasks, false)

    C_lo  = C.ColorYUV(
    \           off_u=off_u_lo,  off_v=off_v_lo)
    C_mid = C.ColorYUV(
    \           off_u=off_u_mid, off_v=off_v_mid)
    C_hi  = C.ColorYUV(
    \           off_u=off_u_hi,  off_v=off_v_hi)

    return MergeLMH(C, C_lo, C_mid, C_hi, showmasks=showmasks) 
}

# http://forum.doom9.org/showthread.php?p=1691736#post1691736
#######################################
### merge Lo, Mid, Hi clips based on clip "C" luma
##
## @ xover_x   - aproximate 50% luma blend between ranges 
##                  default 102 (40%), 191 (75%)
## @ showmasks - if true, show original + 3 masks in quad split
##
function MergeLMH(clip C, clip "C_lo", clip "C_mid", clip "C_hi",
\           float "xover_lomid", float "xover_midhi",
\           bool "showmasks")
{
    xlo   = Min(Max(  0, Default(xover_lomid, 102)), 127) * 3.0 / 256
    xhi   = Min(Max(128, Default(xover_midhi, 191)), 255) * 3.0 / 256
    showmasks = Default(showmasks, false)

    ## (mt_lutxyz too slow; use mt_lut x3)

    mask_lo  = C.mt_lut(
    \   yexpr="x -0.01 * "+String(xlo)+" + 256 * ",
    \   u=-128, v=-128)
    
    mask_hi  = C.mt_lut(
    \   yexpr="1 x -0.01 * "+String(xhi)+" + - 256 * ",
    \   u=-128, v=-128)
    
    mask_mid = mt_lutxy(mask_lo, mask_hi, 
    \   "x  y + -1 * 256 + ", 
    \   u=-128, v=-128)

    R = C
    R = (!IsClip(C_lo))  ? R : R.Overlay(C_lo,  mask=mask_lo)
    R = (!IsClip(C_mid)) ? R : R.Overlay(C_mid, mask=mask_mid)
    R = (!IsClip(C_hi))  ? R : R.Overlay(C_hi,  mask=mask_hi)
    
    return (showmasks==false) ? R
    \  : StackVertical(
    \       StackHorizontal(C, mask_lo),
    \       StackHorizontal(mask_mid, mask_hi)
    \    ).BilinearResize(C.Width, C.height)
    \     .Subtitle("Low",    align=9)
    \     .Subtitle("\nMid",  align=4, lsp=0)
    \     .Subtitle("\nHigh", align=6, lsp=0)
}
raffriff42 is offline   Reply With Quote
Old 27th November 2014, 17:24   #4  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
Thanks, that's what I was looking for.
I don't understand exactly, where is function in the script, which calculates the values, that are in curves of the graph of black body ... such a script should be in the "list of external plugins" - there is no plugin for change of color temperature
Stormborec is offline   Reply With Quote
Old 27th November 2014, 17:46   #5  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
It doesn't work to me ... "invalid arguments to function CheapColorTemp"

I tried:

imagesource("z4xkepN.jpg").converttoyv12
CheapColorTemp(offset_mid=1)

or

c=imagesource("z4xkepN.jpg").converttoyv12
CheapColorTemp(offset_mid=1)
Stormborec is offline   Reply With Quote
Old 27th November 2014, 17:56   #6  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
Shouldn't there be something like "last" or "input" instead "clip C"?
Stormborec is offline   Reply With Quote
Old 27th November 2014, 18:45   #7  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
Quote:
Originally Posted by Stormborec View Post
It doesn't work to me ... "invalid arguments to function CheapColorTemp"

I tried:

imagesource("z4xkepN.jpg").converttoyv12
CheapColorTemp(offset_mid=1)

or

c=imagesource("z4xkepN.jpg").converttoyv12
CheapColorTemp(offset_mid=1)
.
Tried so...
.
c=imagesource("z4xkepN.jpg").converttoyv12
CheapColorTemp(c, 1, 1, 1)
.
You need to call CheapColorTemp() function with three integer arguments. Integer "1" is for example.
.
Code:
#######################################
### emulate color temperature changes in three luma ranges
##
## @ offset_x - arbitrary units; <0 means lower temp (warmer colors)
##     (input range is unlimited, but is normally around -20 to +20; default 0)
##
function CheapColorTemp(clip C, 
\            int offset_lo, int offset_mid, int offset_hi)
{
    Assert(C.IsYUV, "CheapColorTemp: source must be YUV")

    return C.ColorYUVx3(
    \          off_u_lo =offset_lo,  off_v_lo =Round(-0.7*offset_lo),
    \          off_u_mid=offset_mid, off_v_mid=Round(-0.7*offset_mid),
    \          off_u_hi =offset_hi,  off_v_hi =Round(-0.7*offset_hi))
}

#######################################
### apply ColorYUV U & V offsets to three luma ranges
##
## @ off_x   - see ColorYUV
## @ xover_x - aproximate 50% luma blend between ranges
##     ( no reason to mess with this)
## @ showmasks - if true, show original + 3 masks in quad split
##
function ColorYUVx3(clip C,
\           float "off_u_lo", float "off_u_mid", float "off_u_hi",   
\           float "off_v_lo", float "off_v_mid", float "off_v_hi",
\           float "xover_lomid", float "xover_midhi",
\           bool "showmasks")
{
    off_u_lo  = Float(Default(off_u_lo,  0.0))
    off_u_mid = Float(Default(off_u_mid, 0.0))
    off_u_hi  = Float(Default(off_u_hi,  0.0))
    off_v_lo  = Float(Default(off_v_lo,  0.0))
    off_v_mid = Float(Default(off_v_mid, 0.0))
    off_v_hi  = Float(Default(off_v_hi,  0.0))
    xlo = Min(Max(  0, Default(xover_lomid, 102)), 127) * 3.0 / 256
    xhi = Min(Max(128, Default(xover_midhi, 191)), 255) * 3.0 / 256
    showmasks = Default(showmasks, false)

    C_lo  = C.ColorYUV(off_u=off_u_lo,  off_v=off_v_lo)
    C_mid = C.ColorYUV(off_u=off_u_mid, off_v=off_v_mid)
    C_hi  = C.ColorYUV(off_u=off_u_hi,  off_v=off_v_hi)

    ## mt_lutxyz too slow!!

    mask_lo  = C.mt_lut(
    \   yexpr="x -0.01 * "+String(xlo)+" + 256 * ",
    \   u=-128, v=-128)
    
    mask_hi  = C.mt_lut(
    \   yexpr="1 x -0.01 * "+String(xhi)+" + - 256 * ",
    \   u=-128, v=-128)
    
    mask_mid = mt_lutxy(mask_lo, mask_hi, "x  y + -1 * 256 + ", u=-128, v=-128)
    
    return (showmasks)
    \  ? StackVertical(
    \       StackHorizontal(C, mask_lo),
    \       StackHorizontal(mask_mid, mask_hi))
    \       .BilinearResize(C.Width, C.height)
    \       .Subtitle("Low",    align=9)
    \       .Subtitle("\nMid",  align=4, lsp=0)
    \       .Subtitle("\nHigh", align=6, lsp=0)
    \  : C.Overlay(C_lo,  mask=mask_lo)
    \       .Overlay(C_mid, mask=mask_mid)
    \       .Overlay(C_hi,  mask=mask_hi)
}
.
__________________
Warm and fuzzy (white and fluffy)

Last edited by Jenyok; 27th November 2014 at 18:56.
Jenyok is offline   Reply With Quote
Old 27th November 2014, 20:07   #8  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
Super! Now it works ...

Are rusults of this script equivalent of: coloryuv(off_u=x,off_v=y)???
Stormborec is offline   Reply With Quote
Old 27th November 2014, 20:23   #9  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
You need to give values for all arguments, as I didn't bother to make them optional with default values (sorry about that).

So to give a video a lower color temperature (more yellow, less blue), use something like
Code:
CheapColorTemp(0, -5, 0)
or for a higher color temperature (more blue), use something like
Code:
CheapColorTemp(0, 5, 0)

Quote:
Originally Posted by Stormborec View Post
Are results of this script equivalent of: coloryuv(off_u=x,off_v=y)???
Yes, more or less; the problem with simply calling coloryuv is that the highlights and lowlights are altered more than they should be (ie, there is too much saturation in blacks and whites).

Last edited by raffriff42; 27th November 2014 at 20:38.
raffriff42 is offline   Reply With Quote
Old 28th November 2014, 19:03   #10  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
Quote:
Originally Posted by Stormborec View Post
Super! Now it works ...

Are rusults of this script equivalent of: coloryuv(off_u=x,off_v=y)???
.
Where are you from? mate ?
.
__________________
Warm and fuzzy (white and fluffy)
Jenyok is offline   Reply With Quote
Old 28th November 2014, 20:34   #11  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
Czech (Nedvěd, Rosický, Čech )
Stormborec is offline   Reply With Quote
Old 28th November 2014, 21:15   #12  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
http://imgur.com/xrwqvuF

My TV does something else - grass goes to yellow, but the faces are also yellow, rather than red (like on the first screenshot) ...
I think, the TV works with every shade separately (just like the color management / calibration) and there is no global method, how to compensate the color shift ...
Stormborec is offline   Reply With Quote
Old 28th November 2014, 21:34   #13  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
The picture on my tv looks nearly like on this screenshot, so I can insert inverted line, if I want get the correct colors. But it's only approximate:
http://imgur.com/epMbn95

some undersaturation + colorshift

In the coloryuv there are yet gain and gamma parameters, but it's too complicated. I didn't manage research, how gain and gamma work in this tool. But gain is according to the documentation rather used for luma.

Maybe "tweak" should be able to change separate color ranges, but I'm afraid, on my TV are the color shifts done depending on different colors tints and also levels of brightness. So it's practically impossible to make the correction.

Last edited by Stormborec; 28th November 2014 at 21:51.
Stormborec is offline   Reply With Quote
Old 28th November 2014, 22:53   #14  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
I should have read your first post more completely. This seems like a TV calibration or video driver issue, and not a good application for Avisynth.

It's nearly impossible to calibrate colors looking at normal program material. If your video driver includes a calibration routine (mine is called "display optimization wizard") use it before doing anything else. For professional or semipro use, use a proper colorimeter.

Then check video playback with test patterns, especially gray scale ramp, available at http://w6rz.net/. Instructions are available at the link.
raffriff42 is offline   Reply With Quote
Old 29th November 2014, 05:02   #15  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
Quote:
Originally Posted by Stormborec View Post
Czech (Nedvěd, Rosický, Čech )
chill, i heard there're lots of hotties there
feisty2 is offline   Reply With Quote
Old 29th November 2014, 11:39   #16  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
Like everywhere else ...

Thanks. I think, it would be overkill to buy a colorimetr ... I think, I've got relatively well calibrated monitor, therefore the easiest solution could be to compare different levels of gray on the TV and on the monitor. My idea was to put some lightweight script of Avisynth into ffdshow.

Maybe if I took part of the script - just off_u, off_v in two or three levels of brightness ... set the correct parameters and then I could play with colors without changing gray balance - maybe by setting cont_u, cont_v - if I managed figure out how it works separately (I know, that cont_u and cont_v with the same values just means saturation change)

btw. Should I use opt="coring" in coloryuv for my purposes?
Stormborec is offline   Reply With Quote
Old 29th November 2014, 21:07   #17  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
"Maybe if I took part of the script - just off_u, off_v in two or three levels of brightness ..."

Is it correct - just copy the function ColorYUVx3 from raffriff42's script without any changes? It seems, that it works many thanks, raffriff42

btw. why is there the comment: "## mt_lutxyz too slow!!" ?

Pity that I don't understand masktools ...

Code:
function ColorYUVx3(clip C,
\           float "off_u_lo", float "off_u_mid", float "off_u_hi",   
\           float "off_v_lo", float "off_v_mid", float "off_v_hi",
\           float "xover_lomid", float "xover_midhi")
{
    off_u_lo  = Float(Default(off_u_lo,  0.0))
    off_u_mid = Float(Default(off_u_mid, 0.0))
    off_u_hi  = Float(Default(off_u_hi,  0.0))
    off_v_lo  = Float(Default(off_v_lo,  0.0))
    off_v_mid = Float(Default(off_v_mid, 0.0))
    off_v_hi  = Float(Default(off_v_hi,  0.0))


### What makes the calculation: * 3.0 / 256?
### The smooth transition between the ranges ?

    xlo = Min(Max(  0, Default(xover_lomid, 102)), 127) * 3.0 / 256
    xhi = Min(Max(128, Default(xover_midhi, 191)), 255) * 3.0 / 256

  

    C_lo  = C.ColorYUV(off_u=off_u_lo,  off_v=off_v_lo)
    C_mid = C.ColorYUV(off_u=off_u_mid, off_v=off_v_mid)
    C_hi  = C.ColorYUV(off_u=off_u_hi,  off_v=off_v_hi)

  
    mask_lo  = C.mt_lut(
    \   yexpr="x -0.01 * "+String(xlo)+" + 256 * ",
    \   u=-128, v=-128)
    
    mask_hi  = C.mt_lut(
    \   yexpr="1 x -0.01 * "+String(xhi)+" + - 256 * ",
    \   u=-128, v=-128)
    
    mask_mid = mt_lutxy(mask_lo, mask_hi, "x  y + -1 * 256 + ", u=-128, v=-128)
    
    return C.Overlay(C_lo,  mask=mask_lo)
    \       .Overlay(C_mid, mask=mask_mid)
    \       .Overlay(C_hi,  mask=mask_hi)
}
Stormborec is offline   Reply With Quote
Old 2nd December 2014, 16:01   #18  |  Link
LemMotlow
Registered User
 
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 237
Quote:
Originally Posted by raffriff42 View Post
I should have read your first post more completely. This seems like a TV calibration or video driver issue, and not a good application for Avisynth.

It's nearly impossible to calibrate colors looking at normal program material. If your video driver includes a calibration routine (mine is called "display optimization wizard") use it before doing anything else. For professional or semipro use, use a proper colorimeter.

Then check video playback with test patterns, especially gray scale ramp, available at http://w6rz.net/. Instructions are available at the link.
Agreed. 100%.

You don't calibrate a graphic or video to look good on your TV or monitor. That would mean making a different version of every video for every TV or monitor you use. It's nonsense. You calibrate the TV or monitor to established standards of accuracy as well as you can, then adjust your images to display properly on a standardized device. Not the other way around.

Quote:
Originally Posted by Stormborec View Post
The picture on my tv looks nearly like on this screenshot, so I can insert inverted line, if I want get the correct colors. But it's only approximate:
http://imgur.com/epMbn95
The color balance in the top image of your pic looks nearly correct. The bottom image is too red.

Quote:
Originally Posted by Stormborec View Post
In the coloryuv there are yet gain and gamma parameters, but it's too complicated. I didn't manage research, how gain and gamma work in this tool. But gain is according to the documentation rather used for luma.
ColorYUV documentation in Avisynth looks pretty clear to me. If you don't get an understanding of concepts like gain, gamma, black levels, white balance, gray balance, all you'll do is work against yourself. Without histograms, graphs, or test patches, you'll get nowhere. It's impossible to correct color properly by eyeball alone. Why do you think advanced software from Adobe and Vegas have those features? They're not just for looks. Even Avisynth and VirtualDub have similar helpers available.

Quote:
Originally Posted by Stormborec View Post
Maybe "tweak" should be able to change separate color ranges, but I'm afraid, on my TV are the color shifts done depending on different colors tints and also levels of brightness. So it's practically impossible to make the correction.
Tweak is too basic for what you're trying to do, and you don't know how it works anyway. I agree, it's difficult to correct complex color ranges with Tweak, but it does work well as a starting point and is often essential.

Quote:
Originally Posted by Stormborec View Post
it would be overkill to buy a colorimetr ... I think, I've got relatively well calibrated monitor, therefore the easiest solution could be to compare different levels of gray on the TV and on the monitor.
That defies the laws of physics and of logic. A PC monitor or a TV can't be properly calibrated without a colorimeter -- which is simply a precise measuring tool, far more accurate than your eyes. The software used with that tool is your guide to proper adjustment. Without those tools you're like the blind leading the blind. Specifically, the image controls available on the typical consumer monitor are totally inadequate for proper calibration. You need tools designed for the job.

There's enough documentation and instructional material around to contradict everything you're doing. Every working graphics artist, photog, and videographer, and advanced video hobbyist knows very well that you're taking the wrong approach. You can even find calibration and colorimeter videos on YouTube. Free.

An older version of standard TV/projector calibration done the right way (still works for you and me): http://www.curtpalme.com/forum/viewtopic.php?t=10457

Don't buy the calibration software hyped by Curt Palme. For TV, use the free stuff (HCFR): http://www.homecinema-fr.com/colorim...fr-colormeter/

Test example of how to calibrate a PC monitor the right way, this one using an i1 Display2 and XRite: http://www.tftcentral.co.uk/reviews/...e_display2.htm
The new version of the i1 is the I1 Profiler. Used in the same manner. Also used to calibrate your TV with HCFR software.

Example of proper monitor calibration from a member I used to know in another forum (and from my home state, too!): Post shows graphic analysis by HCFR software using the tools described. http://forum.videohelp.com/threads/3...=1#post2083260

Otherwise, I'm afraid you'll have to live with what you get on your own.

Last edited by LemMotlow; 2nd December 2014 at 16:21.
LemMotlow is offline   Reply With Quote
Old 4th December 2014, 19:10   #19  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
You are right. Your solution is true, when it's possible.
I've got only integrated GPU and my cheap TV has only minimum toggles like "contrast", "saturation". So, the software solution is only solution.
Stormborec is offline   Reply With Quote
Old 4th December 2014, 19:27   #20  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 158
I know, what the parameters in coloryuv mean. I don't know what they exactly do. E.g. coring - works it the way like: 15>>>16, 10>>>16, 1>>>16 or rather 15>>>20, 10>>>18, 1>>>16
Stormborec is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:34.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.