八度(Matlab)中复杂函数的域着色(色轮)图 [英] Domain coloring (color wheel) plots of complex functions in Octave (Matlab)

查看:341
本文介绍了八度(Matlab)中复杂函数的域着色(色轮)图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到域或色轮绘图对于复杂功能来说是典型的.

I understand that domain or color wheel plotting is typical for complex functions.

令人难以置信的是,我在网络搜索中找不到一百万以上的回报,无法轻松地让我重现Wikipedia中的某些艺术品:

Incredibly, I can't find a million + returns on a web search to easily allow me to reproduce some piece of art as this one in Wikipedia:

有一个在线资源可以复制黑色为零的图-不错全部...但是,我想在Octave中请求一些简单的带注释的代码,以生成复数函数的彩色图.

There is this online resource that reproduces plots with zeros in black - not bad at all... However, I'd like to ask for some simple annotated code in Octave to produce color plots of functions of complex numbers.

这里是一个例子:

我在此处代码以绘制复杂函数.但是,它使用了另一种技术,高度代表函数图像的Re部分,颜色代表虚部:

I see here code to plot a complex function. However, it uses a different technique with the height representing the Re part of the image of the function, and the color representing the imaginary part:

推荐答案

Peter Kovesi 有一些梦幻般的色彩图.他提供了 MATLAB函数,称为colorcet ,我们可以在此处使用要获得循环颜色图,我们需要表示相位. 在运行下面的代码之前,请下载此功能.

Peter Kovesi has some fantastic color maps. He provides a MATLAB function, called colorcet, that we can use here to get the cyclic color map we need to represent the phase. Download this function before running the code below.

让我们开始创建一个复数值测试函数f,其中幅度从中心开始增加,并且相位等于围绕中心的角度.就像您显示的示例一样:

Let's start with creating a complex-valued test function f, where the magnitude increases from the center, and the phase is equal to the angle around the center. Much like the example you show:

% A test function
[xx,yy] = meshgrid(-128:128,-128:128);
z = xx + yy*1i;
f = z;

接下来,我们将获取其相位,将其转换为colorcet C2颜色图(具有循环性)的索引,最后将其重塑为原始函数的形状. out这里有3个尺寸,前两个是原始尺寸,最后一个是RGB. imshow将这样的3D矩阵显示为彩色图像.

Next, we'll get its phase, convert it into an index into the colorcet C2 color map (which is cyclic), and finally reshape that back into the original function's shape. out here has 3 dimensions, the first two are the original dimensions, and the last one is RGB. imshow shows such a 3D matrix as a color image.

% Create a color image according to phase
cm = colorcet('C2');
phase = floor((angle(f) + pi) * ((size(cm,1)-1e-6) / (2*pi))) + 1;
out = cm(phase,:);
out = reshape(out,[size(f),3]);

最后一部分是使用f的大小来调制这些颜色的强度.为了使不连续性为2的幂,我们以2为底的对数,应用模运算,然后再次计算2的幂.与out的简单乘法会在必要时降低颜色的强度:

The last part is to modulate the intensity of these colors using the magnitude of f. To make the discontinuities at powers of two, we take the base 2 logarithm, apply the modulo operation, and compute the power of two again. A simple multiplication with out decreases the intensity of the color where necessary:

% Compute the intensity, with discontinuities for |f|=2^n
magnitude = 0.5 * 2.^mod(log2(abs(f)),1);
out = out .* magnitude;

最后一个乘法在Octave和更高版本的MATLAB中有效.对于旧版本的MATLAB,您需要改用bsxfun:

That last multiplication works in Octave and in the later versions of MATLAB. For older versions of MATLAB you need to use bsxfun instead:

out = bsxfun(@times,out,magnitude);

最后,使用imshow进行显示:

% Display
imshow(out)

请注意,这里的颜色比您的示例中的更多静音. colorcet色图在感知上是统一的.这意味着相同的角度变化会导致相同的颜色感知变化.在您发布的示例中,例如,黄色是一个非常窄的明亮带.这样的条带会导致功能中某些功能的错误突出显示,这可能根本不相关.感知均匀的颜色图对于正确解释数据非常重要.还请注意,此特定颜色图在四个基本方向上具有易于命名的颜色(紫色,蓝色,绿色,黄色).纯实数值是绿色(正)或紫色(负),而纯虚数值是蓝色(正)或黄色(负).

Note that the colors here are more muted than in your example. The colorcet color maps are perceptually uniform. That means that the same change in angle leads to the same perceptual change in color. In the example you posted, for example yellow is a very narrow, bright band. Such a band leads to false highlighting of certain features in the function, which might not be relevant at all. Perceptually uniform color maps are very important for proper interpretation of the data. Note also that this particular color map has easily-named colors (purple, blue, green, yellow) in the four cardinal directions. A purely real value is green (positive) or purple (negative), and a purely imaginary value is blue (positive) or yellow (negative).

这篇关于八度(Matlab)中复杂函数的域着色(色轮)图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆