Matlab图形调色

Simple example

var colormap = require('colormap')
options = {
  colormap: 'jet',   // pick a builtin colormap or add your own 
  nshades: 72,       // how many divisions 
  format: 'hex',     // "hex" or "rgb" or "rgbaString" 
  alpha: 1           // set an alpha value or a linear alpha mapping [start, end] 
}
cg = colormap(options)

where leaving options = {} or undefined results in the defaults given above. There is a minimum number of nshadesdivisions you can select since the algorithms for each colormap have different requirements. colormap throws an error if there are too few divisions for the chosen colormap and gives the minimum number required. You should be safe with n > 10 for all the colormaps, though some require much less (much simpler to implemenent).

Options

The colormap can be any of the supported builtin colormaps. Or you can add your own. For an example of how to add your own see the json format available at:

colorscales = require('colormap/colorScales')

Colorscales are a sequence of objects containing an index and rgb key. The index defines how fast or slow the rgb values will change from one segment to the next. Ie.the steepness of the gradient between two segments. The rgb parameter can hold a length 3 or 4 array, depending if alpha values are included in the mapping.

Return values

An array of hex values ('hex') or an array of length 4 arrays containing rgba values ('rgb') or an rgba css string ('rgbaString').

Complete Example

This example will produce the colormap image used at top of this README. It uses all built in color maps and utilizes alpha channel mapping.

var cmap = require('./..'),
    canvas = document.getElementById('canvas'),
    img = document.getElementById('background'),
    c = canvas.getContext('2d'),
    n = 48,
    colormaps = [
        'jet', 'hsv','hot','cool','spring','summer','autumn','winter','bone',
        'copper','greys','YIGnBu','greens','YIOrRd','bluered','RdBu','picnic',
        'rainbow','portland','blackbody','earth','electric'
    ];
 
img.onload = run;
 
function drawColorMaps (colormap, name, height) {
    /*
     * Build up the color ranges and add text
     */
    for (var j = 0; j < n; j++) {
        c.fillStyle = colormap[j];      // start ind at index 0 
        c.fillRect(j*10, height, 10, 40);
 
    }
    c.fillStyle = '#262626';
    c.font = '16px Helvetica';
    c.fillText( name, n*10 + 10, height + 26);
}
 
function run() {
    var height, colormap;
    c.canvas.height = colormaps.length * 40 + img.height;
    c.canvas.width = 648;
 
    for (var i = 0; i < colormaps.length; i++) {
        height = i*40;
        colormap = cmap({
            colormap: colormaps[i],
            nshades: n,
            format: 'rgbaString'
        });
        drawColorMaps(colormap, colormaps[i], height);
    }
 
    /*
     * Now lets try some alpha maps overtop an image!
     */
    var ilast = i;
    c.drawImage(img, 0, i*40, 480, 240);
 
    // remove background img 
    img.parentElement.removeChild(img);
 
    for (var i = 0; i < colormaps.length; i++) {
        height = (ilast + i)*40;
        colormap = cmap({
            colormap: colormaps[i],
            nshades: n,
            format: 'rgbaString',
            alpha: [0, 1]
        });
        drawColorMaps(colormap, colormaps[i] + ' with transparency', height);
    }
}

Then just browserify it and throw it in some html and it will output the image above!

Matlab图形调色的更多相关文章

  1. MATLAB学习笔记(十)——MATLAB图形句柄

    (一)图形对象及其句柄 一.图形对象 MATLAB图形对象包括: 1.MATLAB每一个具体图形一定包括计算机屏幕和图形窗口两个对象 二.图形对象句柄 1.定义 MATLAB在创建每一个图形对象时,都 ...

  2. 【转】MATLAB图形句柄(二)

        MATLAB图形句柄   1.1 图形对象及其句柄 1.2 图形对象属性 1.3 图形对象的创建 1.1 图形对象及其句柄 1.图形对象 MATLAB的图形对象包括计算机屏幕.图形窗口.坐标轴 ...

  3. MATLAB 图形图像处理

    theme: MATLAB author: pprp date: 2018/2/2 --- MATLAB 图形图像处理 二维绘图命令 plot 线性空间 plot(t,[x1,x2,x3]) : 在同 ...

  4. windows 下 putty 登陆服务器 显示matlab图形界面

    本文需要下载 putty.exe 和 pscp.exe :http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Xming 主 ...

  5. MATLAB学习笔记(十一)——MATLAB图形用户界面设计

    (一)菜单设计 一.建立用户菜单 1.概况: 用户菜单一般含有一级菜单和二级菜单,乃至多级菜单.每一级菜单又包含多个菜单项.建立菜单可以使用uimenu函数. 2.uimenu函数调用: %建立一级菜 ...

  6. matlab图形句柄属性总结

    原文在于雪漫的bloghttp://blog.sina.com.cn/s/blog_4b9b714a0100cce2.html这两天在看句柄式图形方面的东西,以下是我在看书过程中整理的学习笔记,比较详 ...

  7. matlab图形矢量化解决方案

    大致思路:matlab中生成矢量格式文件-导入Visio中-编辑-导出合适格式-在其他软件中使用 准备工具 Matlab 2014b或更高版本 Visio 2007或更高版本 我查看过,Matlab能 ...

  8. 【转】matlab图形句柄详解(一)

    在matlab中,每一个对象都有一个数字来标识,叫做句柄.当每次创建一个对象时,matlab就为它建立一个唯一的句柄,句柄中包含有该对象的相关信息参数,可以在后续程序中进行操作,改变其中的参数,以便达 ...

  9. MATLAB 图形着色

    1.matlab中的颜色查找表函数: (1)autumn:从红色向橘黄色.黄色平稳过渡: (2)bone:为含有较高的蓝色组分的gray颜色查找表: (3)colorcube:包含RGB颜色空间中尽可 ...

随机推荐

  1. Gh0st整理资料1

    题首 Gh0st是一款开源的远程控制软件.界面友好,性能高效.网上流传很多版本,比如红狼,饭客,败笔,大灰狼版本以及多如牛毛的个人修改的如外星人,Drat等个人修改版本.但内核都是基于Gh0st3.6 ...

  2. 转:好用 Eclipse插件收集与说明

    http://developer.51cto.com/art/201007/214478.htm

  3. linux 硬连接与软连接

    1.linux中文件占用一个inode,inode指向文件内容.2.文件名可以认为是一个指针,指向inode.硬连接相当于指针的整体拷贝,并不是对文件内容的拷贝.两个文件名(两个指针)都能修改文件,删 ...

  4. 微信小程序 - 生命周期

    生命周期 1.小程序注册完成后,加载页面,触发onLoad方法.(切记,onShow和onLoad的区别,onShow是每当进入这个页面时就会触发,而onload是载入进来时才触发) 2.页面载入后触 ...

  5. PHP高级教程-多维数组

    PHP 多维数组 一个数组中的值可以是另一个数组,另一个数组的值也可以是一个数组.依照这种方式,我们可以创建二维或者三维数组: 实例 <?php // 二维数组: $cars = array ( ...

  6. ora01219数据库未打开

    今天连接数据后,一看提示ora01219数据库未打开,关了服务重开仍然是这样,在度娘找了下才发现问题 应该是我删除了一个数据文件,看下解决办法 错误原因: 直接关闭数据库,然后删除DBF文件.即表空间 ...

  7. 用 Eclipse 插件提高代码质量

    如果能在构建代码前发现代码中潜在的问题会怎么样呢?很有趣的是,Eclipse 插件中就有这样的工具,比如 JDepend 和 CheckStyle,它们能帮您在软件问题暴露前发现这些问题.在 让开发自 ...

  8. java面试第七天

    反射: 反射:在运行时动态分析或使用一个类进行工作. java.lang.Class类:描述类信息的类. 类对象:描述一个类信息的对象,当虚拟机加载类的时候,就会创建这个类的类对象并加载该对象,Cla ...

  9. Javascript获取当月的天数

    var d = new Date(); var curMonthDays = new Date(d.getFullYear(), (d.getMonth() + 1), 0).getDate(); a ...

  10. 开源大数据技术专场(下午):Databircks、Intel、阿里、梨视频的技术实践

    摘要: 本论坛第一次聚集阿里Hadoop.Spark.Hbase.Jtorm各领域的技术专家,讲述Hadoop生态的过去现在未来及阿里在Hadoop大生态领域的实践与探索. 开源大数据技术专场下午场在 ...