Skip to main content
gamedev.net
🔒 Locked

Gradients

Started by Nicodemus 3 replies 550+ views
Original Post
Nicodemus
Nicodemus
Hi, I have an image with a gradient between two colours. What I need to know is: given any pixel of the image, and without any information about the gradient (only the two colours are known), know how much percent of each colour is present in that pixel (example: 25% percent colour 1, 75% colour 2). Any ideas? Thanks, Nicodemus. ---- "When everything goes well, something will go wrong." - Murphy
Nicodemus.----"When everything goes well, something will go wrong." - Murphy
wcreviston
wcreviston
I don''t know exactly what your setup is, but I''ll pretend you''re using a 64x64 image with red on the left blending into blue on the right.

If you want to get the color of the gradient 16 pixels from the left of the image, divide that into the width of the image to get a percentage.
16 / 64 = 0.25 or 25%. In this case, you have 25% red and
(100 - 25) = 75% blue.



Nicodemus
Nicodemus
Sorry, I didn't explained very well. The problem is that I may have an image like this:



Notice that the gradient is not linear through the image's length. Any help will be appreciated.

Thanks,

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy


Edited by - Nicodemus on October 2, 2000 2:21:38 PM
Nicodemus.----"When everything goes well, something will go wrong." - Murphy
Painless
Painless
I don''t think it''s really possible to tell with just the two colors and one color from between them, except for cases like black/white.. for example, if the two colors are different shades of gray, you could get one color between them with many different mixes.
Nicodemus
Nicodemus
Hi,

Thanks for the replies.
I was told to use linear algebra, like this: Let A and B be the two colours that the gradient goes between, C the cross product between A and B, and D the test colour:

// cross product
Cr = Ag*Bb - Ab*Bg
Cg = Ab*Br - Ar*Bb
Cb = Ar*Bg - Ag*Br


[Ar Br Cr] [Dr] [x]
[Ag Bg Cg].[Dg]=[y]
[Ab Bb Cb] [Db] [z]


x = Ar*Dr + Br*Dg + Cr*Db
y = Ag*Dr + Bg*Dg + Cg*Db
z = Ab*Dr + Bb*Dg + Cb*Db



x was suppose to return how much of colour A is in colour D, and the same with y and colour B, but that didn't work either, x and y always return the same value (x = y), independent of D's value. My vector/matrix math might be wrong (I've no references with me at the moment), but I don't think that's the case. Any other idea?

Thanks,

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy


Edited by - Nicodemus on October 3, 2000 4:03:10 PM
Nicodemus.----"When everything goes well, something will go wrong." - Murphy

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.