【问题标题】:Color Ranges in ILNumerics Surface PlotILNumerics 曲面图中的颜色范围
【发布时间】:2014-07-23 21:40:14
【问题描述】:

我正在使用 ILNumerics 生成曲面图。

我想使用平面阴影颜色图(即颜色范围)而不是平滑阴影颜色图(即每个像素都有自己的颜色)。

ILNumerics 可以做到这一点吗?

平面阴影图和彩条图例示例:

Smooth-Shaded 曲面图和彩条图例示例:

【问题讨论】:

    标签: colors ilnumerics color-mapping


    【解决方案1】:

    您可以创建一个显示平面着色行为的颜色图。只需复制公共颜色图中存在的关键点,以便对分配相同颜色的一系列颜色数据进行建模。

    平面阴影颜色图的工作原理

    根据documentation,颜色图的关键点由 5 列组成:一个“位置”和 4 个颜色值 (RGBA)。为了对“平面”着色颜色图进行建模,请将两个关键点“几乎”完全重叠放置,将第一个关键点设置为下一个较低范围的颜色,将第二个关键点设置为下一个较高范围的颜色。因此,颜色范围由分配了相同颜色的两个关键点建模。

    我在上面的段落中写了“几乎”,因为我认为您必须在两个范围的边缘之间至少留下一个微小的间隙 - 希望没有实际的颜色数据值会达到那个间隙。但似乎根本不需要间隙,并且可以为两个关键点完全相同赋予相同的值。但是你在排序时必须小心:不要混合颜色(ILMath.sort() 中的快速排序不稳定!)

    在以下示例中,从Colormaps.Jet 创建平面阴影颜色图:

    Keypoints for Colormaps.Jet (original, interpolating)
    <Single> [6,5]
    [0]:          0          0          0     0,5625          1 
    [1]:     0,1094          0          0     0,9375          1 
    [2]:     0,3594          0     0,9375          1          1 
    [3]:     0,6094     0,9375          1     0,0625          1 
    [4]:     0,8594          1     0,0625          0          1 
    [5]:          1     0,5000          0          0          1 
    

    由此衍生的平面着色版本:

    Colormaps.Jet - flat shading version
    <Single> [11,5]
    [0]:          0          0          0     0,5625          1 
    [1]:     0,1094          0          0     0,5625          1 
    [2]:     0,1094          0          0     0,9375          1 
    [3]:     0,3594          0          0     0,9375          1 
    [4]:     0,3594          0     0,9375          1          1 
    [5]:     0,6094          0     0,9375          1          1 
    [6]:     0,6094     0,9375          1     0,0625          1 
    [7]:     0,8594     0,9375          1     0,0625          1 
    [8]:     0,8594          1     0,0625          0          1 
    [9]:     1,0000          1     0,0625          0          1 
    [10]:          1     0,5000          0          0          1 
    

    如您所见,我在CreateFlatShadedColormap() 中犯了一个错误:永远不会使用 (0.5,0,0,1) 的最后一个关键点。我会把它留作练习来解决这个问题...... ;)

    全平面阴影示例

    private void ilPanel1_Load(object sender, EventArgs e) {
        ILArray<float> A = ILMath.tosingle(ILSpecialData.terrain["0:400;0:400"]);
        // derive a 'flat shaded' colormap from Jet colormap
        var cm = new ILColormap(Colormaps.Jet);
        ILArray<float> cmData = cm.Data;
        cmData.a = Computation.CreateFlatShadedColormap(cmData);
        cm.SetData(cmData); 
        // display interpolating colormap
        ilPanel1.Scene.Add(new ILPlotCube() { 
            Plots = {
                new ILSurface(A, colormap: Colormaps.Jet) {
                    Children = { new ILColorbar() },
                    Wireframe = { Visible = false }
                }
            }, 
            ScreenRect = new RectangleF(0,-0.05f,1,0.6f)
        }); 
    
        // display flat shading colormap
        ilPanel1.Scene.Add(new ILPlotCube() {
            Plots = {
                new ILSurface(A, colormap: cm) {
                    Children = { new ILColorbar() },
                    Wireframe = { Visible = false }
                }
            },
            ScreenRect = new RectangleF(0, 0.40f, 1, 0.6f)
        }); 
    
    }
    
    private class Computation : ILMath {
        public static ILRetArray<float> CreateFlatShadedColormap(ILInArray<float> cm) {
            using (ILScope.Enter(cm)) {
                // create array large enough to hold new colormap
                ILArray<float> ret = zeros<float>(cm.S[0] * 2 - 1, cm.S[1]);
                // copy the original
                ret[r(0, cm.S[0] - 1), full] = cm; 
                // double original keypoints, give small offset (may not even be needed?) 
                ret[r(cm.S[0], end), 0] = cm[r(1, end), 0] - epsf;
                ret[r(cm.S[0], end), r(1, end)] = cm[r(0, end - 1), r(1, end)];
                // reorder to sort keypoints in ascending order
                ILArray<int> I = 1;
                sort(ret[full, 0], Indices: I);
                return ret[I, full];
            }
    
        }
    

    结果

    【讨论】:

    • 虽然我接受了这个答案,但情节仍然不是平坦的阴影。这可以通过放大或使用不太密集的数据集很容易地看到。正如@user492238 所指出的,颜色总是在数据点之间插值(平滑阴影)。
    • 对。如果碰巧有瓷砖为它们的任何顶点选择不同的颜色,颜色仍然会被插值。我想知道你的平面阴影表面是如何定义来处理这种情况的?哪种颜色将用于整个瓷砖区域?对应于平均值的颜色?但这有什么用呢?另外,请考虑更新您的问题,因为它指的是“平面阴影 color map”。这就是答案给出的。
    【解决方案2】:

    这是不可能的。 ILNumerics 中的曲面图总是在网格点之间插入颜色。对于其他着色模型,您必须创建自己的表面类。

    【讨论】:

    • OP 不是要求 ILSurface,而是要求“平面着色颜色图”。我认为值得尝试创建一个显示所描述颜色分布的颜色图?
    • 我添加了一个答案。效果很好。
    猜你喜欢
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多