将复数编码为 RGB 像素并返回

发布于 2024-08-27 03:18:22 字数 605 浏览 6 评论 0原文

如何更好地将复数编码为 RGB 像素,反之亦然?

可能绝对值(的对数)属于亮度,而参数则属于色调。

去饱和像素应该在逆变换中接受随机参数。

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

有现成的公式吗?

编辑:看起来我只需要将 RGB 转换为 HSB 并返回。

编辑2:现有RGB -> HSV 转换器片段:

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

我不想要 0。我想要随机。不仅仅是如果hsv.sat==0,而是如果它低于它应该的值(“应该是”意味着最大饱和度,从复数转换后的饱和度)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烙印 2024-09-03 03:18:22

你会遇到很多问题:

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

假设你的复数集是有限且离散的,我认为 RGB 的最佳方法系统是这样的:
笛卡尔轴:

alt text

极轴:

替代文字
(来源:sitmo.com)

我认为它将是独特的并且有点语义:比如计数器网格和地理地图的着色以及医学图像分析。

您可以使用 HSL 系统和极轴:

alt text

您想用此编码做什么?

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
(source: sitmo.com)

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?

打小就很酷 2024-09-03 03:18:22

首先对您的问题进行一些评论:

  • 1+i -> (510,255,0)?
  • “亮度”和“色调”通常是
    HSV 颜色模型的组成部分
    而不是 RGB

也许您可以使用复数的极坐标形式并将它们映射到色轮,例如具有 V 固定的 HSV ?由于复数的大小可能是无限的,因此您可能无法将它们映射到任何颜色模型,所有这些(好吧,我所知道的所有颜色模型都是有界的)。也许您可以使用非欧几里得几何将复数映射到单位圆中。

但是,为了回答你的问题,我从未遇到过任何现成的解决方案来解决你的问题。

我们等待向SO学习。

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.

¢好甜 2024-09-03 03:18:22

OP 似乎有一个不同的问题……但无论如何,这里有一个地方包含了这个问题。它是 GPL 代码,因此您可以根据需要使用它。

Sage 的 complex_to_rgb 函数可以执行此操作,使用 Numpy 和 Python。 Mathematica 有如此复杂的情节(事实上,Sage 的灵感来自于它们),所以想必它的内部也有类似的东西,尽管可能不是代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文