View Full Version : Apply two 3x3 matrices to each pixel?
MrPete
21st January 2015, 04:54
What I want:
For each pixel of each frame
{
// Transform the (R, G, B) values by doing two matrix
// transformatoins:
A = (R * ConstRa) + (G * ConstGa) + (B * ConstBa)
B = (R * ConstRb) + (G * ConstGb) + (B * ConstBb)
C = (R * ConstRc) + (G * ConstGc) + (B * ConstBc)
pxR' = (A * ConstAr) + (B * ConstBr) + (C * ConstCr)
pxG' = (A * ConstAg) + (B * ConstBg) + (C * ConstCg)
pxB' = (A * ConstAb) + (B * ConstBb) + (C * ConstCb)
pxRGB = (pxR', pxG', pxB')
}
I have not found such a plugin/function... seems like it MUST already exist... Any ideas?
PS: Why... for arbitrary colorspace conversion using known (rgb)->xyz, xyz -> (r'g'b') matrices
In my case, I've captured video on my wive's Nikon DSLR in Adobe RGB, and want to convert back to normal sRGB...
Thanks!
Pete
poisondeathray
21st January 2015, 05:56
Maybe ManualColorMatrix ?
http://forum.doom9.org/showthread.php?t=161777
Or one of the 3DLut functions like t3dlut, with a custom LUT
EDIT: It looks like yCMS supports AdobeRGB , sRGB, R'G'B' and the regular 709/601 YUV, so you could generate a LUT with yCMS
MrPete
25th February 2015, 13:45
Got waylaid by the ice (2 broken ribs, ouch!) then a trip to the Netherlands (yay!)
So... First idea -- ManualColorMatrix() would work except it truncates the intermediate results. Now I'm thinking about eliminating the intermediate. It's been too long since I did matrix math at school... Anybody remember off the top of their head how to combine two matrix operations into one?
So I have the following:
Cxyz = Crgb * (3 x 3 matrix RGBxyz)
Crgb' = Cxyz * (3 x 3 matrix XYZrgb')
(All matrices nicely provided at http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html)
Bottom Line Question for solution #1: How do I calculate the direct (3x3?) matrix for Crgb -> Crgb' conversion?
Idea #2 - yCMS. Interesting! (For future readers, look here: http://yesgrey.com/ycms.html)
I've got some playing to do on that one... will return with what it takes to make it work in a bit...
THANKS MUCHLY!!!!
colours
26th February 2015, 03:33
See: https://en.wikipedia.org/wiki/Matrix_multiplication#Square_matrices. (I could explain it in words, but I guess it's easier to see a concrete example.) If you want, you can also feed your matrices to WolframAlpha and let WA multiply the matrices for you.
Also, you have to be careful about whether you're left-multiplying or right-multiplying the matrices, and the order you're multiplying the two transition matrices. Your equations seem to suggest that you're working with row vectors, so you have to take the transpose of the matrices given in that RGB/XYZ Matrices page.
MrPete
27th February 2015, 05:33
Thanks, colours! Good reminder.
Well, yCMS turned out to be a quick and relatively painless solution.
a) Install tritical's t3dlut plugin, and go get yCMS (standalone exe package)
b) Define the following control file for yCMS:
# Example input file for yCMS v1.0 and up
#
# Convert 8 bit Adobe RGB to sRGB (HD resolutions)
# Set input format
Input_Format HD RGB_PC 8
# Set output format
Output_Format HD RGB_PC 8
# define input Adobe RGB
Input_Primaries 4
Input_Transfer_Function 5
#define output sRGB
Output_Primaries 0
Output_Transfer_Function 0
c) Run yCMS "mycontrolfile.txt" my3dlutfile
d) Include this plugin call in avs: c.t3dlut("my3dlutfile.3dlut")
Done.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.