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

Thread Tools Search this Thread Display Modes
Old 21st January 2015, 04:54   #1  |  Link
Registered User
MrPete's Avatar
Join Date: Dec 2014
Location: @2100m in Colorado USA
Posts: 55
Apply two 3x3 matrices to each pixel?

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...

MrPete is offline   Reply With Quote
Old 21st January 2015, 05:56   #2  |  Link
Registered User
Join Date: Sep 2007
Posts: 3,586
Maybe ManualColorMatrix ?

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

Last edited by poisondeathray; 21st January 2015 at 07:17.
poisondeathray is offline   Reply With Quote
Old 25th February 2015, 13:45   #3  |  Link
Registered User
MrPete's Avatar
Join Date: Dec 2014
Location: @2100m in Colorado USA
Posts: 55
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....YZ_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...

MrPete is offline   Reply With Quote
Old 26th February 2015, 03:33   #4  |  Link
Registered User
colours's Avatar
Join Date: Mar 2014
Posts: 312
See: https://en.wikipedia.org/wiki/Matrix...quare_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.
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 27th February 2015, 05:33   #5  |  Link
Registered User
MrPete's Avatar
Join Date: Dec 2014
Location: @2100m in Colorado USA
Posts: 55
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")

MrPete is offline   Reply With Quote

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 19:35.

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