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 28th December 2014, 11:45   #1  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Something like RGBAdjust but in YUV

RGBAdjust:


rb, gb, bb

"OFFSETS rb, gb, bb - add a value to the red, green, blue" (the same could be done in coloryuv - in YUV)


r, g, b

"red (/green/blue) is scaled. For example, a scale of 3.0 MULTIPLIES the red channel of each pixel by 3"

- I doubt it would go something like this done in YUV, but I mean something else ...


The third, which isn't yet possible in RGB nor in YUV is:

OFFSET of chroma, but with values multiplied by level of LUMA of each pixel



black - no shift
white - max shift

Exists the WhiteBalance plugin, but it is relatively inaccurate - changing some value only by 1 step do big color change ...
Stormborec is offline   Reply With Quote
Old 28th December 2014, 13:41   #2  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
Even if there's no currently existing filter to do exactly what you want, it's not hard to throw something together using Masktools.

Code:
source
y = converttoy8()
u = utoy8()
v = vtoy8()
y_adjusted = mt_lut(y,expr="x")
u_adjusted = mt_lutxy(u,y,expr="x y 16 - 0.1 * +")
v_adjusted = mt_lutxy(v,y,expr="x y 16 - 0.1 * +")
ytouv(u_adjusted,v_adjusted,y_adjusted) # note that the order here is U, V, Y
Tweak the expr parameters to taste; if you want higher precision, look into using CLExpr with lsb=true.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 28th December 2014, 15:33   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
r, g, b

"red (/green/blue) is scaled. For example, a scale of 3.0 MULTIPLIES the red channel of each pixel by 3"

- I doubt it would go something like this done in YUV, but I mean something else ...
ColorYUV uses weird int gain arg, where eg
int gain_y = 0 is same as usual float gain=1.0 (no change)
int gain_y = 256 is same as usual float gain=2.0
int gain_y = 512 is same as usual float gain=3.0
int gain_y = -256 is same as usual float gain=0.5

See ColorYUV docs.

EDIT:
Cont_u=256 : Cont_v=256 : Same as Saturation * 2.0
ColorYUV2(), also has SPow (S shaped power curve) as well as RPow (As gamma).

ColorYUV2 here: http://forum.doom9.org/showthread.ph...ight=coloryuv2
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th December 2014 at 16:22.
StainlessS is offline   Reply With Quote
Old 28th December 2014, 19:29   #4  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
colours:

many thanks
I had in mind masktools, but the strange writing
of its functions will be forever a secret for me

Could you describe, what the script actually do?
I'm going to test it ...


StainlessS:

I am surprised that until now I have not come across your Coloryuv2 ...

The gain in ColorYUV is analogy of contrast in Tweak. For chroma it is useless, because of the strange chroma waveform.

Every parameter in this basic internal functions is independent of the others.
Stormborec is offline   Reply With Quote
Old 28th December 2014, 19:38   #5  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
Quote:
Originally Posted by colours View Post
Even if there's no currently existing filter to do exactly what you want, it's not hard to throw something together using Masktools.

Code:
source
y = converttoy8()
u = utoy8()
v = vtoy8()
y_adjusted = mt_lut(y,expr="x")
u_adjusted = mt_lutxy(u,y,expr="x y 16 - 0.1 * +")
v_adjusted = mt_lutxy(v,y,expr="x y 16 - 0.1 * +")
ytouv(u_adjusted,v_adjusted,y_adjusted) # note that the order here is U, V, Y
This only produces correct results with YV24, for YV12 I guess one needs to use a scaled luma for U/V adjustment (not sure if if chroma placement matters here)?
Reel.Deel is offline   Reply With Quote
Old 28th December 2014, 19:39   #6  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
y = converttoy8() # ... creating "y clip" without chroma from "last"
u = utoy8() # ... creating "u clip" without chroma with values from chroma u in "last"
v = vtoy8() # ... creating "v clip" without chroma with values from chroma v in "last"
y_adjusted = mt_lut(y,expr="x") # ... crating some mask from luma of "last" ???
u_adjusted = mt_lutxy(u,y,expr="x y 16 - 0.1 * +") # ... some aplication of the mask on "chroma u" ???
v_adjusted = mt_lutxy(v,y,expr="x y 16 - 0.1 * +") # ... some aplication of the mask on "chroma v" ???
ytouv(u_adjusted,v_adjusted,y_adjusted) # ... gluing back together ???
Stormborec is offline   Reply With Quote
Old 28th December 2014, 19:41   #7  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Reel.Deel: you mean - the fact, that chroma is quarter of luma in YV12?
Stormborec is offline   Reply With Quote
Old 28th December 2014, 19:49   #8  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
http://imgur.com/rya4YFO

It's great !! I will further test it ...
Stormborec is offline   Reply With Quote
Old 28th December 2014, 19:51   #9  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
@Stormborec

This is what I mean:
Code:
y = converttoy8()
u = utoy8()
v = vtoy8()
y_scaled = y.bicubicresize(width(u), height(u))
y_adjusted = mt_lut(y,expr="x")
u_adjusted = mt_lutxy(u,y_scaled,expr="x y 16 - 0.1 * +")
v_adjusted = mt_lutxy(v,y_scaled,expr="x y 16 - 0.1 * +")
ytouv(u_adjusted,v_adjusted,y_adjusted) # note that the order here is U, V, Y
Reel.Deel is offline   Reply With Quote
Old 28th December 2014, 20:01   #10  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Good news - on grayscale it works perfect, from black to white !!!
Stormborec is offline   Reply With Quote
Old 28th December 2014, 20:04   #11  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
And the resize will affect the result, or it is just for computing values for masktools? I mean if using bilinear or lanczos does matter ...
Stormborec is offline   Reply With Quote
Old 28th December 2014, 20:12   #12  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
The scaled luma is only use for the chroma adjustment in MaskTools. You can try a different resizer but I'm not sure how it will affect the output. As always, you're welcome to try and report back
Reel.Deel is offline   Reply With Quote
Old 28th December 2014, 20:39   #13  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Many thanks !!!

BlankClip(length=1,width=640,height=360,fps=25,pixel_type="yv12",color=$ffffff)
levels(0,1,255,0,235)

y = converttoy8()
u = utoy8()
v = vtoy8()
y_scaled = y.bicubicresize(width(u), height(u))
y_adjusted = mt_lut(y,expr="x")
u_adjusted = mt_lutxy(u,y_scaled,expr="x y 16 - 0.05 * +")
v_adjusted = mt_lutxy(v,y_scaled,expr="x y 16 - 0.0 * +")
a = ytouv(u_adjusted,v_adjusted,y_adjusted)


interleave(a,last)
converttorgb.rgbadjust(analyze=true)
#coloryuv(analyze=true)

I've tested different colors and it works exactly as I wanted
Stormborec is offline   Reply With Quote
Old 28th December 2014, 21:43   #14  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
I made from your code a function:

Code:
function Colorsbyy( clip last, float "ou", float "ov" )

{


ou = default(ou/219, 0.0)
ov = default(ov/219, 0.0)


y = converttoy8()
u = utoy8()
v = vtoy8()
y_scaled = y.bilinearresize(width(u), height(u))
y_adjusted = mt_lut(y,expr="x")
u_adjusted = mt_lutxy(u,y_scaled,expr="x y 16 - "+string(ou)+" * +")
v_adjusted = mt_lutxy(v,y_scaled,expr="x y 16 - "+string(ov)+" * +")
ytouv(u_adjusted,v_adjusted,y_adjusted)

return last

}



I added: /219, in order to the output looked - when input is a monochromatic image with luma = 235 - same like by using coloryuv(off_u, off_v).

I'll still test different resizers ...

So I tested spline36resize vs. bilinearresize - by using coloryuv(analyze=true) - there is a "one or two number" change, but it isn't a chance to see the change, although I sharpened, brightened and enlarged the image 3× ...

spline36resize vs. bilinearresize - the speed is about 3 % higher for bilinear ...

Last edited by Stormborec; 28th December 2014 at 23:42.
Stormborec is offline   Reply With Quote
Old 28th December 2014, 23:57   #15  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Do you guys never use the cont_u and cont_v arguments of ColorYUV? It stretches the chroma channels from the center:

it stretches the signal out from the center. That means that if the contrast is set to 0, it preserves the values as they are. When the contrast is 256 all values are multiplied by 2 (twice as bright). If the contrast is 512 all values are multiplied by 3. Thus if cont = k*256 for some integer k (and zero gain) then Y becomes Y + k*(Y-128) (idem for the chroma). Although it is possible, it doesn't make sense to apply this setting to the luma of the signal.

So setting cont_u = 512 (=2*256) means that U becomes: U_new = U_old + 2*(U_old-128).

You need to set opt=coring to clamp the values to tv-levels. Or isn't this what you want?


@Reel.Deel,

What are you trying to do in your script above? My polish is very bad, but i guess i need to read it as follows:

// u_adjusted = mt_lutxy(u,y_scaled,expr="x y 16 - 0.1 * +")
u_adjusted = 0.1 * (16 - y_scaled) + u

Doesn't make much sense to me, but perhaps i completely misread it ... Why do you need a 2d lut table at all?

Last edited by Wilbert; 29th December 2014 at 00:20.
Wilbert is offline   Reply With Quote
Old 29th December 2014, 00:02   #16  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
SmoothAdjust works fine (16 bitdepth), you can try it.

http://forum.doom9.org/showthread.php?t=154971
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 29th December 2014, 01:11   #17  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
Quote:
Originally Posted by Wilbert View Post
@Reel.Deel,

What are you trying to do in your script above?
colours (post #2) came up with this, I just added a small change.

Quote:
Originally Posted by Wilbert View Post
My polish is very bad, but i guess i need to read it as follows:

// u_adjusted = mt_lutxy(u,y_scaled,expr="x y 16 - 0.1 * +")
u_adjusted = 0.1 * (16 - y_scaled) + u
To me RPN and LUTs are like black magick . Fortunately MaskTools has mt_infix/mt_polish.

mt_infix("x y 16 - 0.1 * +") returns this: x+((y-16)*0.1)
Reel.Deel is offline   Reply With Quote
Old 29th December 2014, 04:29   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by Wilbert View Post
Do you guys never use the cont_u and cont_v arguments of ColorYUV?
You talkin' to me? You talkin' to me? You talkin' to me? Then who the hell else are you talking... you talking to me? Well I'm the only one here. Who the f*** do you think you're talking to? Oh yeah? OK.

__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 29th December 2014, 04:59   #19  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
SmoothAdjust is just other very very slow overkill for me

I know cont_u, cont_v very well. It's equivalent for saturation if it is used both ones.



OT.:
BlankClip(length=125,width=640,height=360,fps=25,pixel_type="yv12",color=$0000e2)
coloryuv(analyze=true)

=> y=38 ; u=227 ; v=112 ; r=0 ; g=0 ; b=225

BlankClip(length=125,width=640,height=360,fps=25,pixel_type="yv12",color=$0000ff)
coloryuv(off_y=-25)
coloryuv(analyze=true)

=> y=16 ; u=240 ; v=110 ; r=0 ; g=0 ; b=226

The color is nearly the same. So what does the big different in yuv mean? Am I dreaming or awake ???
Stormborec is offline   Reply With Quote
Old 29th December 2014, 05:14   #20  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
why do you just have to adjust colors under yuv colorspace?
if ur clip is ycbcr
you can see y as green (obviously not actual green tho)
u as blue (not actual blue also)
v as red

let's say you wanna enhance blue a little bit
mt_lut ("x 128 > x 128 - 1.24 * 128 + x 128 - 0.72 * 128 + ?", y=2, u=3, v=2) might help
# ((x > 128) ? (x - 128) * 1.24 + 128 : (x - 128) * 0.72 + 128)

Last edited by feisty2; 29th December 2014 at 05:17.
feisty2 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 07:55.


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