Log in

View Full Version : LumaDifference & ChromaDifference


mathmax
22nd December 2011, 22:22
Hi,

I would like to make two videos match in term of color and brightness. I intend to use the functions LumaDifference, ChromaUDifference and ChromaVDifference (http://avisynth.org/mediawiki/Internal_functions/Runtime_functions) and correct the differences frame by frame, but I face two problems:

- these functions return a value between 0 and 255 of the absolute difference between two planes. I would like to have a relative value or a mean to know which clip is brighter or more colored.

- once I get the difference, can I correct using the function coloryuv() ? How to use the values returned by LumaDifference, ChromaUDifference and ChromaVDifference as parameters for coloryuv()? The scale doesn't seem to be the same.. :-/

StainlessS
23rd December 2011, 00:21
This does not answer your question, but you might want to tryout 'ColorLike()', which I believe
does what you are trying to achieve.


EDIT:- Here,
http://forum.doom9.org/showthread.php?t=96308&highlight=colorlike

Gavino
23rd December 2011, 00:58
As StainlessS suggests, ColourLike might be a better way to achieve what you want, but to answer your questions:
these functions return a value between 0 and 255 of the absolute difference between two planes. I would like to have a relative value or a mean to know which clip is brighter or more colored.
Use AverageLuma/ChromaU/ChromaV on each clip separately to get the absolute value for each clip. In fact, the XXXDifference values are just the absolute difference between these two values.

once I get the difference, can I correct using the function coloryuv() ? How to use the values returned by LumaDifference, ChromaUDifference and ChromaVDifference as parameters for coloryuv()? The scale doesn't seem to be the same.. :-/
The off_y, off_u and off_v parameters of ColorYUV correspond directly to these values (and on the same scale).

Gavino
23rd December 2011, 10:56
Use AverageLuma/ChromaU/ChromaV on each clip separately to get the absolute value for each clip. In fact, the XXXDifference values are just the absolute difference between these two values.
Sorry, I was wrong about the last bit.
The absolute difference is calculated for each pixel and then averaged over all pixels.
So LumaDifference(c1, c2) is not the same thing as abs(AverageLuma(c1)-AverageLuma(c2)).

mathmax
23rd December 2011, 20:30
This does not answer your question, but you might want to tryout 'ColorLike()', which I believe
does what you are trying to achieve.
Yes I already tried ColorLike() before.. but I was not so happy with the result. I will try again on these videos.

Sorry, I was wrong about the last bit.
The absolute difference is calculated for each pixel and then averaged over all pixels.
So LumaDifference(c1, c2) is not the same thing as abs(AverageLuma(c1)-AverageLuma(c2)).
Thank you for explaining this. In fact AverageLuma/Chroma fits my need :)


The off_y, off_u and off_v parameters of ColorYUV correspond directly to these values (and on the same scale).

It doesn't seem to be the case :-/ Moreover, an offset lower than 0.5 seems to be ignored...


ScriptClip("""
d1 = AverageChromaU(clip1) - AverageChromaU(clip2)
d2 = AverageChromaV(clip1) - AverageChromaV(clip2)
d3 = AverageLuma(clip1) - AverageLuma(clip2)

Subtitle(string(d1), 30, 0)
Subtitle(string(d2), 30, 20)
Subtitle(string(d3), 30, 40)
""")


before correction:
http://img819.imageshack.us/img819/5208/screens0000.jpg

after correction:
clip2 = clip2.coloryuv(off_U=0.22,off_V=0.57, off_Y=4.27)
http://img856.imageshack.us/img856/253/screens20000.jpg

Gavino
23rd December 2011, 21:22
It doesn't seem to be the case :-/ Moreover, an offset lower than 0.5 seems to be ignored...
The output pixel values are (necessarily) rounded to the nearest integer, so
clip2 = clip2.coloryuv(off_U=0.22, off_V=0.57, off_Y=4.27)
will have the same effect as
clip2 = clip2.coloryuv(off_U=0, off_V=1, off_Y=4)
which is what your result shows.

mathmax
24th December 2011, 00:07
mmm.. ok...
as you see, I tried to stack 2 videos in order to get rid of logos and writings.. but after correction, I don't think it looks better finally :-/

The problem is that the two clips fluctuates in term of color and brightness.. sometimes one is darker than the other and a few frames later, it's the contrary.

That's why I wanted to correct these differences frame by frame.. and I don't think colorlike() can do that, am I wrong?

Would there be anything to improve or should I give up definitely my idea?

thanks for the advices :)

mathmax
1st January 2012, 12:00
any advice?