views:

182

answers:

3

How is it better to encode a complex number into RGB pixel and vice versa?

Probably (logarithm of) an absolute value goes to brightness and an argument goes to hue.

Desaturated pixes should receive randomized argument in reverse transformation.

Something like:
0 -> (0,0,0)
1 -> (255,0,0)
-1 -> (0,255,255)
0.5 -> (128,0,0)
i -> (255,255,0)
-i -> (255,0,255)

(0,0,0) -> 0
(255,255,255) -> e^(i * random)
(128,128,128) -> 0.5 * e^(i *random)
(0,128,128) -> -0.5

Are there ready-made formulas for that?

Edit: Looks like I just need to convert RGB to HSB and back.

Edit 2: Existing RGB -> HSV converter fragment:

if (hsv.sat == 0) {
    hsv.hue = 0; // !
    return hsv;
}

I don't want 0. I want random. And not just if hsv.sat==0, but if it is lower that it should be ("should be" means maximum saturation, saturation that is after transformation from complex number).

A: 

First a couple of comments on your question:

  • 1+i -> (510,255,0) ?
  • 'brightness' and 'hue' are usually components of an HSV colour model rather than RGB

Perhaps you could use polar form of complex numbers and map them to a colour wheel such as HSV with V fixed ? Since the magnitude of a complex number can be infinite, you might have trouble mapping them to any colour model, all of which (well, all the ones I know of that is) are bounded. Perhaps you could use a non-Euclidean geometry for mapping complex numbers into the unit circle.

But, to answer your question, I've never come across any ready-made solution to your problem.

We wait to learn from SO.

High Performance Mark
Magnitude is limited (logarithm is cropped to upper or lower bound if exceed). Yes, I use polar form. I was looking to RGB-HSV-RGB converter (probably already found it). I only need to know how much random part should I add in the reverse transformation.
Vi
Well, if you'd asked for what you wanted, you'd have got more useful answers.
High Performance Mark
+4  A: 

You will have many problems:

|RGB|=2^24 and |C|=?

Supposing your complex numbers set is finite and discrete, i think the best method for RGB System is like this:
Cartesian Axis:

alt text

Polar Axis:

alt text

i think it will be unique and a little semantic: something like counter grids and coloring of geographical maps and medical images analysis.

you can use HSL system and polar axis instead:

alt text

what you want to do with this encoding?

Sorush Rabiee
I'm converting sound to picture and back. Sound is split to the intersecting fragments, each of them FFTed, resulting numbers are logarithmed. Grayscale variant already works and sounds (argument is just discarded at conversion to the picture and randomized at conversion from picture). It works, but sounds blurred. I want to save argument information in colour of pixes, as both are circular.
Vi
@ Vi: are you trying to implement a sound graph? i'm nut sure but this could help: http://faculty.washington.edu/dillon/PhonResources/javoice/vowjavoice2.html read it's algorithm.
Sorush Rabiee
@ Vi: which encoding structure you are converting to images?
Sorush Rabiee
@Sorush Rabiee What is "encoding structure"? Current chain is Sound -> Chunks -(FFT)-> Complex number arrays -> Image rows -> Image. I just want to add colour to the image (and argument to complex number arrays).
Vi
Finished up with this scheme: `hue += (0xFF*random()) + (rgb_max - rgb-min)` `num = exp((value-255)/25 + i*(hue*2*pi/256))`. Converts, plays.
Vi
A: 

Hi, How abt it's inverse: encode RGB to complex domain?

Mojgan Hashemian
It's not an answer. Please move it into comments of this question.
Sorush Rabiee
Not normally possible. Colours are 3-dimensional, complex numbers are 2-dimensional. I mapped subset of complex numbers to 2-dimensional subset of colours (without greyish under-saturated ones). In the reverse transformation I've just assigned random colour to "grey" things.
Vi