Log in

View Full Version : ManualColorMatrix - Can perform any matrix-based color conversion


xv
1st July 2011, 13:49
This plug-in can perform any matrix-based color conversion (if you know how to use it :)):
Out Add Matrix In
/ \ / \ / \ / \
| Y | | yadd | | yy yu yv | | Y |
| U | = | uadd | + | uy uu uv | * | U |
| V | | vadd | | vy vu vv | | V |
\ / \ / \ / \ /
Supports YV24, RGB24 and RGB32 input and YV24, RGB24, RGB32, YUY2 and YV12 output.

Examples:

Convert YCgCo to RGB32:
ManualColorMatrix(2, 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, -1.0, 0.0, -128.0, 256.0)

Convert RGB to YV24 (bt601 matrix, range 16-235):
ManualColorMatrix(0, 0.255785, 0.504129, 0.097906, -0.148223, -0.290992, 0.439215, 0.439215, -0.367789, -0.071426, 16.0, 128.0, 128.0)

Convert YCgCo to YUY2 (bt601 matrix, range 16-235):
ManualColorMatrix(3, 0.85782, 0.150438, 0.157879, 0.0, -0.581984, -0.587438, 0.0, -0.735578, 0.510641, -23.4645, 277.686, 156.792)

http://www.mediafire.com/?9yyj1uepe5ir5w7

pandy
1st July 2011, 18:50
THX and waiting for YV12/YUY2 input support (and interlace as for YV12 if this is possible)

xv
1st July 2011, 23:52
Even for YV12->YV12 or YUY2->YUY2 transform I would have to convert it internally to YV24 first, there is no way to do the color conversion with chroma subsampled material. That would mean I would do it the same way I did with YUY2/YV12 output, calling a resizer and upsample chroma.
For interlaced material I cannot use a resizer, but you could just do SeperateFields().ManualColorMatrix(...).Weave()

Gavino
2nd July 2011, 08:41
For interlaced material I cannot use a resizer, but you could just do SeperateFields().ManualColorMatrix(...).Weave()
Why can't you use a resizer?
You could do the equivalent of my YV12ToYUY2i_26 function in this post.

Note that if ManualColorMatrix did support YV12 input, SeperateFields().ManualColorMatrix(...).Weave() would give incorrect results, since separated YV12 fields have a different chroma placement.

xv
2nd July 2011, 14:57
Your script only works with AviSynth 2.6, in Avisynth 2.6 you can just convert to YV24 and convert back to YV12 afterwards, no reason to double that functionality in this plugin.

Could you please explain the problem with SeperateFields and Weave, I could do that internally and use different chroma offsets, but I do not see what chroma offset I should use at the moment (you can use the nice image on page 381 in H.264 standard to explain: http://www.itu.int/rec/T-REC-H.264-201003-I/en )

Gavino
2nd July 2011, 17:11
Your script only works with AviSynth 2.6, in Avisynth 2.6 you can just convert to YV24 and convert back to YV12 afterwards, no reason to double that functionality in this plugin.
Agreed.

Could you please explain the problem with SeperateFields and Weave, I could do that internally and use different chroma offsets, but I do not see what chroma offset I should use at the moment
Basically, you would do the equivalent of what I did for the 2.5 version in that same post (function YV12ToYUY2i), where the (vertical) offset is 0.125 (1/8) for top fields and -0.125 for bottom fields. This is because, although the chroma placement in the frame is the same for both progressive and interlaced, once separated it has a different relationship to luma (because the luma spacing has doubled).
See http://avisynth.org/mediawiki/Sampling#YV12_color_format.

xv
2nd July 2011, 17:58
Thatīs the same for MPEG-2 / MPEG-1 subsampling (type 0 and 1 in H.264 spec) if I see that correct? For type 2/3 subsampling (as in H.264 spec) it should be +0.25 for top field and 0 for bottom field, for type 4/5 itīs 0 for top field and -0.25 for bottom field?

Gavino
2nd July 2011, 18:52
Yes, all correct.

And conversely for output (downsampling from YV24), all those offsets get multiplied by -2.

I think I'll have to lie down for a while - my eyes and brain are still recovering from viewing that funky diagram Figure E-1 in the H.264 spec. :)

jmac698
11th July 2011, 19:22
There's still stuff missing, I wish it could do this
http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
That would make it a lot more complicated though, I might have to script it myself.. or get back into figuring out how to make a plugin.
Man, if I could make plugins, I would be one of the most prolific ones here :)

Soulnight
14th October 2018, 17:16
What happens if you for example convert from RGB REC2020 to RGB rec709 with the correct conversion matrix?

All the color outside REC709 will have illegal values.

Are the illegal RGB value left "untouched", negative etc... or are they getting clipped to the nearest legal value?

Thank you!