473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ColorMatrix - What do all the values do??

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,
Feb 22 '06 #1
5 9286
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

--
HTH
Stoitcho Goutsev (100)
Feb 22 '06 #2

Stoitcho Goutsev (100) wrote:
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.

--
Larry Lard
Replies to group please

Feb 23 '06 #3
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" <la*******@hotmail.com> wrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...

Stoitcho Goutsev (100) wrote:
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.

--
Larry Lard
Replies to group please

Feb 23 '06 #4

Stoitcho Goutsev (100) wrote:
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 ?

--
Larry Lard
Replies to group please

Feb 23 '06 #5
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.
--

Stoitcho Goutsev (100)

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...

Stoitcho Goutsev (100) wrote:
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 ?

--
Larry Lard
Replies to group please

Feb 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve Hall | last post by:
Folks, My secnario involves two tables - ObservationRegister, and Person. ObservationRegister contains most of the "useful" fields, including the UserID of the person that raised the record, and...
1
by: Bill Petzke | last post by:
I am of the understanding that a ColorMatrix can be used to adjust the contrast of an image. Any idea how this is done?
2
by: Henry Wu | last post by:
Hi I was at the search for making e.Graphics.DrawImage turn any image to Grayscale, and I found two similar solutions but different ColorMatrix values, what is the difference between the two? Is...
6
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like...
2
by: Hennie | last post by:
I apologise if this is a stupid question, but I would appreciated any help on this subject. I want to create a view (VIEW_1 in example below) where I take numeric values from a field in one...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
13
by: Gregor =?UTF-8?B?S292YcSN?= | last post by:
Hi! With VALUES you can do something like: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER) which will give you: LETTER NUMBER ------ ------ A 1 B 2...
0
by: Lloyd Dupont | last post by:
in GDI+ you can customize image drawing with a ColorMatrix. it's a nice way to turn a bitmap to grey or another color. I wonder if there is such a thing available in WPF? at leats I can't find...
8
by: gigonomics | last post by:
Hi all, I hope someone can help me out. I need to return the best available seats subject to the constraint that the seats are side by side (or return X consecutive records from a table column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.