ColorMatrix - What do all the values do??

M

Mark Ingram

Right, ive got the following array with which to setup a color matrix.

bm[0][0] = 1; bm[0][1] = 0; bm[0][2] = 0; bm[0][3] = 0; bm[0][4] = 0;
bm[1][0] = 0; bm[1][1] = 1; bm[1][2] = 0; bm[1][3] = 0; bm[1][4] = 0;
bm[2][0] = 0; bm[2][1] = 0; bm[2][2] = 1; bm[2][3] = 0; bm[2][4] = 0;
bm[3][0] = 0; bm[3][1] = 0; bm[3][2] = 0; bm[3][3] = 1; bm[3][4] = 0;
bm[4][0] = brightness; bm[4][1] = brightness; bm[4][2] = brightness;
bm[4][3] = 0; bm[4][4] = 1;


It basically adjusts the brightness of an image whilst preserving the
transparency of the image. However, if "bm[4][3] = 1;" the transparency
is not preserved and is replaced with white.


What do all the values in the array represent? I understand when you
have a normal matrix it doesnt change anything and looks like:

1 0 0
0 1 0
0 0 1


But this is a 5x5 matrix, im guessing 3 are RGB, no idea what eveything
else does.

Can someone shed some light on this for me?

Thanks,
 
S

Stoitcho Goutsev \(100\)

Mark,

Color matrices work in the same way as transformation matrices. Color
matrices works on the same way as transformation matrices with the
difference that they apply on color vectors [RGBAw] where w = 1.
In the docs you can see that the vector the trasnformations are applied on
is ARGB. I believe it was an error in the docs for .NET1.x (only with this I
could explain the unexpected results that I got using ARGB verctor. I
believe the vector is [RGBAw] rather than [ARGBw]. I see that this part of
the docs stay unchanged for .NET 2.0. Since I haven't use them for a long
time I don't know if they changed something there. I doubt it however
because it could've been a compatibility issue.
But this is a 5x5 matrix, im guessing 3 are RGB, no idea what eveything
else does.
as I said 4th is for the transparency and fifth is always 1 to homogenize
the coordinate system.

To transform the color you multiplay the matrix with the [rgba1] vector. if
you want to dim the pixel without changing the trasparency you do

0.5 0 0 0 0
0 0.5 0 0 0
0 0 0.5 0 0 x [RGBA1] = [0.5*R , 0.5*G, 0.5*B, A,
1]
0 0 0 1 0
0 0 0 0 1
 
L

Larry Lard

Stoitcho said:
Mark,

Color matrices work in the same way as transformation matrices. Color
matrices works on the same way as transformation matrices with the
difference that they apply on color vectors [RGBAw] where w = 1.
In the docs you can see that the vector the trasnformations are applied on
is ARGB. I believe it was an error in the docs for .NET1.x (only with this I
could explain the unexpected results that I got using ARGB verctor. I
believe the vector is [RGBAw] rather than [ARGBw]. I see that this part of
the docs stay unchanged for .NET 2.0. Since I haven't use them for a long
time I don't know if they changed something there. I doubt it however
because it could've been a compatibility issue.
But this is a 5x5 matrix, im guessing 3 are RGB, no idea what eveything
else does.
as I said 4th is for the transparency and fifth is always 1 to homogenize
the coordinate system.

Using homogenous coordinates also means that *translations* can be done
in the same system. It helps to know a little about the use of matrices
to represent geometric transformations here, because basically we are
doing exactly the same thing, except that our 'axes' are R G B A
instead of X Y Z.

In 3d space, if we just use 3x3 matrices, the only transformations we
can represent are *linear* - that is, T(a+b) = T(a) + T(b), and by
implication, T(0) = 0 for all transformations T. With this model we can
have rotations, reflections, and skew/shears - but the origin will
always stay in the same place. It would be nice to be able to represent
translations in the same model. We do this with that extra homogenizing
coordinate. Suppose we let

T = 1 0 0 0 / 0 1 0 0 / 0 0 1 0 / a b c 1

We can see that P = (x y z 1)(transpose) will give us TP = (x+a y+b z+c
1), which is the translation we desired. This can of course be combined
with any linear operation in the top left 3x3 of T.

Thus in color space we can implement 'translations' such as adding 0.2
R to the whole color space.
 
S

Stoitcho Goutsev \(100\)

Larry,

That is wonderful explanation. I couldn't have done it so well.

Can you by any chance confirm my observation that the vector that the color
trainsformation are applied, when using ImageAttributes, is RGBAw rather
than ARGBw as the docs claim?

--

Stoitcho Goutsev (100)

Larry Lard said:
Mark,

Color matrices work in the same way as transformation matrices. Color
matrices works on the same way as transformation matrices with the
difference that they apply on color vectors [RGBAw] where w = 1.
In the docs you can see that the vector the trasnformations are applied
on
is ARGB. I believe it was an error in the docs for .NET1.x (only with
this I
could explain the unexpected results that I got using ARGB verctor. I
believe the vector is [RGBAw] rather than [ARGBw]. I see that this part
of
the docs stay unchanged for .NET 2.0. Since I haven't use them for a long
time I don't know if they changed something there. I doubt it however
because it could've been a compatibility issue.
But this is a 5x5 matrix, im guessing 3 are RGB, no idea what eveything
else does.
as I said 4th is for the transparency and fifth is always 1 to homogenize
the coordinate system.

Using homogenous coordinates also means that *translations* can be done
in the same system. It helps to know a little about the use of matrices
to represent geometric transformations here, because basically we are
doing exactly the same thing, except that our 'axes' are R G B A
instead of X Y Z.

In 3d space, if we just use 3x3 matrices, the only transformations we
can represent are *linear* - that is, T(a+b) = T(a) + T(b), and by
implication, T(0) = 0 for all transformations T. With this model we can
have rotations, reflections, and skew/shears - but the origin will
always stay in the same place. It would be nice to be able to represent
translations in the same model. We do this with that extra homogenizing
coordinate. Suppose we let

T = 1 0 0 0 / 0 1 0 0 / 0 0 1 0 / a b c 1

We can see that P = (x y z 1)(transpose) will give us TP = (x+a y+b z+c
1), which is the translation we desired. This can of course be combined
with any linear operation in the top left 3x3 of T.

Thus in color space we can implement 'translations' such as adding 0.2
R to the whole color space.
 
L

Larry Lard

Stoitcho said:
Larry,

That is wonderful explanation. I couldn't have done it so well.

Can you by any chance confirm my observation that the vector that the color
trainsformation are applied, when using ImageAttributes, is RGBAw rather
than ARGBw as the docs claim?

Hmm, well from what I can see the docs I have (VS2003 and VS2005) have
it correct (RGBAw) throughout, eg for ColorMatrix it says "Defines a
5x5 matrix that contains the coordinates for the RGBA space", and all
the samples appear correct also. Have you got a reference for somewhere
that says ARGBw ?
 
S

Stoitcho Goutsev \(100\)

Hmm, I found the problem. It correctly says RGBA in the begining of the
document, but I guess I've always read the Remarks section where one can
find the following:



MSDN .NET2.0:
"The matrix coefficients constitute a 5 x 5 linear transformation that is
used for transforming ARGB homogeneous values. For example, an ARGB vector
is represented as alpha, red, green, blue, and w, where w is always 1."



MSDN .NET 1.1

" Remarks
The matrix coefficients constitute a 5x5 linear transformation that is used
for transforming ARGB homogeneous values. For example, an ARGB vector
represented as alpha, red, green, blue, and w, where w is always 1."


Anyways, that was bugging me since I saw it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top