开发者

Encode complex number as RGB pixel and back

开发者 https://www.devze.com 2022-12-25 05:21 出处:网络
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.

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开发者_如何学JAVA 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).


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?


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.


It seems like the OP had a different question in mind... but anyway, here is one place this is incorporated. It is GPL code, so you can use it if you want.

Sage's complex_to_rgb function does this, with Numpy and Python. Mathematica has such complex plots (Sage's were inspired by them, in fact), so presumably it has something like this internally as well, though perhaps not code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号