thecritter
thecritter

Reputation: 73

A more natural color representation: Is it possible to convert RGBA color to a single float value?

Is it possible to represent an RGBA color to a single value that resembles the retinal stimulation? The idea is something like:

The RGBA colors in between should be represented by values that capture the amount of stimulation they cause to the eye like:

Any ideas on this? Is converting to grayscale the only solution?

Thanks in advance!

Upvotes: 1

Views: 443

Answers (1)

ProgrammersBlock
ProgrammersBlock

Reputation: 6284

Assign specific bits of a single number to each part of RGBA to represent your number. If each part is 8 bits, the first 8 bits can be assigned to R, the second 8 bits to G, the third 8 bits to B, and the final 8 bits to A.

Let's say your RGBA values are= 15,4,2,1. And each one is given 4 bits. In binary, R is 1111, G is 0100, B is 0010, A is 0001. In a simple concatenation, your final number would be 1111010000100001 in binary, which is 62497. To get G out of this, 62497 / 256, round it to an integer, then modulo 16. 256 is 16 to the second power because it is the 2nd position past the first from the right(R would need third power, B would need first power). 16 is 2 to the fourth power because I used 4 bits. 62497 / 256 = 244, 244 % 16 = 4.

Upvotes: 1

Related Questions