Log in

View Full Version : GiCoCu / YUV question - how to add a luma curve properly?


zee944
26th May 2011, 20:01
I'd like to add a luma curve to a video (I mean not touching the colors just making the pixels darker or brighter).

I have this little sample script:

LoadPlugin("GiCoCu.dll")

ImageReader("td_samp.png")
AddLumaCurve("full_flat.amp") # Photoshop curve with full zeros

Function AddLumaCurve(clip src, string curve)
{#
src
ConvertToRGB32
MergeChroma(GiCoCU(curve,photoshop=true).ConvertToYUY2,last.ConvertToYUY2)
ConvertToYV12
Return(last)
}


This is how the sample picture looks like originally:
http://i179.photobucket.com/albums/w286/zee944/td_samp.png

The curve (here: full_flat.amp (http://www.mediafire.com/?ayqfic727ffy4dl)) I'm using here is full of zeros, meaning it should make all the 0..255 values to zeros. (Of course I will never be using a flat curve, it's just for testing.)

So theoretically the end result would be full black. It isn't:

http://i179.photobucket.com/albums/w286/zee944/td_samp_black.png

I have ran into this before and I know it's YUV colorspace behavior and it's because U and V chroma planes are left untouched, but I just can't find the solution to elude the problem. It must be some GreyScale(), ShowRed/Green/Blue and MergeChroma/Luma trick and not even an extremely complicated one, but I'm playing around for hours now and can't figure it out. Can someone help me out? :confused: Thanks in advance.

Dogway
26th May 2011, 22:09
edit:
Mergeluma(AddLumaCurve("full_flat.amp")) ?

IanB
26th May 2011, 23:38
Modifying luma without regard to chroma as well can result in out of gamut values.

For example if Y=16, then U=128 and V=128 are the only valid in gamut values.

Out of gamut values have undefined behaviour when converted back to RGB for eventual display. Avisynth just clamps the individual R, G or B channels to be between 0 and 255 without regard to maintaining either luma, hue or saturation.

See U and V ranges for valid RGB and Understanding YUV, Luma, Luminance for a discussion about this.

zee944
28th May 2011, 11:33
edit:
Mergeluma(AddLumaCurve("full_flat.amp")) ?

Doesn't help. It's trickier than that.


See U and V ranges for valid RGB and Understanding YUV, Luma, Luminance for a discussion about this.

So then I need to substitute the out of gamut (invalid Y, U, V combinations) pixels with black?

How can I take the luma from one clip, the chroma from another clip and merge them together without having the side effects above? Is this calls for some lookup table for the invalid pixels, or is it simpler?