View Full Version : RGB to XYZ colorspace conversion
elmarikon
14th October 2009, 21:22
Hi folks!
I am trying to create content for D-cinema.
Therefor I need to do colorspace conversion to XYZ colorspace.
I found these RGB/XYZ Matrices (http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html) but do not really know how to use the values...
Does anybody have a clue?
All the best!
SwK
Sagekilla
15th October 2009, 03:29
It's easy.. just do the calculations (http://en.wikipedia.org/wiki/Matrix_multiplication#Ordinary_matrix_product).
[X Y Z] = [R G B][a b c]
[d e f]
[g h i]
X = (R * a) + (G * d) + (B * g)
Y = (R * b) + (G * e) + (B * h)
Z = (R * c) + (G * f) + (B * i)
The matrix M, shown below, is the RGB -> XYZ matrix for a given working space. Scroll down on that page you were on and you'll see the matrix M you need to use
[a b c]
M = [d e f]
[g h i]
Adobe RGB -> XYZ matrix:
[0.5767309 0.2973769 0.0270343]
M = [0.1855540 0.6273491 0.0706872]
[0.1881852 0.0752741 0.9911085]
[X Y Z] = [R G B] M
X = (R * 0.5767309) + (G * 0.1855540) + (B * 0.1881852)
Y = (R * 0.2973769) + (G * 0.6273491) + (B * 0.0752741)
Z = (R * 0.0270343) + (G * 0.0706872) + (B * 0.9911085)
Understand now?
elmarikon
15th October 2009, 16:08
Okay, thanx for this explanation!
I do understand this now, I guess...
Now I am to ty out which plugin to use for this case...
thank u!
sh0dan
15th October 2009, 16:25
Your input colorspace is probably sRGB and not Adobe RGB.
And you may need to linearize the sRGB, by applying a reverse gamma of 2.2, and some special cases for very small values:
http://en.wikipedia.org/wiki/SRGB
The linearized sRGB to XYZ is:
0.4124564 0.2126729 0.0193339
0.3575761 0.7151522 0.1191920
0.1804375 0.0721750 0.9503041
(Moved to general development)
elmarikon
16th October 2009, 13:37
ooookay...
so I was trying to get that all into a avisynth script, but with minor success..:-(
I could not figure out how to combine e.g. X = (R * 0.5767309) + (G * 0.1855540) + (B * 0.1881852) into one new channel...
this is my script right now:
vid = Mpeg2source("...").ConvertToRGB24
vidx = RGBAdjust(vid,0.4124564,0.3575761,0.1803475)
vidy = RGBAdjust(vid,0.2126729,0.7151522,0.0721750)
vidz = RGBAdjust(vid,0.0193339,0.1191920,0.9503041)
MergeRGB(vidx,vidy,vidz,"RGB24")
The result is just a little more bluish, then the source...
I guess, it's not that easy, right?!
I attached an image in RGB (the original) and one in xyz colorspace.
The xyz should of cause in the end look the same as the rgb, but since IrfanView or sth. can't deal with xyz it looks LSD-ish:-)
So, I will have to change the colors to make it look as freaky as the xyz image...
:thanks: for your help!
Sagekilla
16th October 2009, 21:49
Avisynth does not support XYZ as far as I know, and if you intend on doing anything serious involving that colorspace, you'll need to get someone (or do it yourself) to add support for XYZ output in avisynth.
Otherwise, your efforts will be (unfortunately) fruitless, since avisynth is limited to YVx and RGB color spaces.
elmarikon
20th October 2009, 14:10
Rite...
I know about that, but by simply recoloring the images, I guess it must be possible to achieve the goal of having some kind of 'fake xyz' or am I wrong?
Has no one got an idea?
Sagekilla
22nd October 2009, 05:02
Sure, you can adjust it so it's
R = X
G = Y
B = Z
But I don't see how that would be useful at all for you, especially since you can't output XYZ from avisynth without writing a plugin.
elmarikon
23rd October 2009, 14:32
So, the idea was to recolor
R-->X
G-->Y
B-->Z
export as raw images or tiffs and interpret as xyz colorspace afterwards.
But I just can't figure out how to recolor properly...
what do u think??
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.