float -> RGB

A

alexxx.magni

Greetings,
I know this isnt a perlish problem,
but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
according to whichever palette you want...
but I'm not expert at all in graphics problems, so it's not clear to
me how to do it - hope somebody can drop down a couple of lines!

thanks...


Alessandro
 
L

Lars Haugseth

Greetings,
I know this isnt a perlish problem,
but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
according to whichever palette you want...
but I'm not expert at all in graphics problems, so it's not clear to
me how to do it - hope somebody can drop down a couple of lines!

You haven't told us what the "float" number represent.
You haven't told us what range the RGB values should have.
You haven't told us what a palette is and how it is stored.

Until you specify this, there are an unlimited number of ways to
do such a mapping.

Here's one:

$R = $G = $B = $x;

Probably not what you want.
 
A

A. Sinan Unur

Greetings,
I know this isnt a perlish problem,
but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
according to whichever palette you want...
but I'm not expert at all in graphics problems, so it's not clear to
me how to do it - hope somebody can drop down a couple of lines!

This is line one.
This is line two.

You are very welcome.

On a more serious note, your question is not well-defined.

Define:

U = [0,1]
R = { 0, 1, 2, ..., 255 }
G = { 0, 1, 2, ..., 255 }
B = { 0, 1, 2, ..., 255 }

Then, the function

f : U -> R x G x B

defined by f(x) = round( (255, 255, 255)*x, 0 )

is a natural mapping of real fractions to RGB triplets.

Now, what do you mean "according to whichever palette you want"?

In any case, note that the answer to some well defined version of your
question is independent of the programming language used but anyone's
ability to provide the answer you are seeking is highly dependent on
your ability to specify the question you want to ask.

Sinan
 
U

Uri Guttman

b> my $triple = $palette[int(256 * $f)];

no need for the int() call as array indexing will do an implied int()
for you.

uri
 
M

Martien Verbruggen

On Fri, 23 Nov 2007 05:00:13 -0800 (PST),
Greetings,
I know this isnt a perlish problem,
but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
according to whichever palette you want...
but I'm not expert at all in graphics problems, so it's not clear to
me how to do it - hope somebody can drop down a couple of lines!

As others have said, it's a bit vague what exactly you're trying to do.
If you're trying to calculate coordinates in different colour spaces,
maybe you can have a look at this:

http://www.manning.com/verbruggen/

Chapter 1 of that book discusses colour spaces, and is available as a
free download from that page. Perl code implementations are discussed in
Appendix B, which is not available online, but the full source code for
the book is also available from the same page, which includes those
pieces of code.

Martien

PS. disclosure: If it wasn't already clear, I am the author of that
book. This post is not meant as an advertisement, which is why I made
sure all relevant content I refer to is available to you for free.
 

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

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,678
Latest member
Aniruddha Das

Latest Threads

Top