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. 【OpenCV】解析OpenCV中copyMakerBorder函数

    Use the OpenCV function :copy_make_border:`copyMakeBorder <>` to set the borders (extra paddin ...

  2. MySql无法远程登录以及IP被锁解决办法

    授权 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;Query OK, 0 rows aff ...

  3. 你使用 Web 平台安装程序命令行工具

    你使用 Web 平台安装程序命令行工具 获取的软件由其所有者授权给你.Microsoft 未授予你第三方软件的任何权利.已成功加载主源: https://go.microsoft.com/?linki ...

  4. sqoop安装部署(笔记)

    sqoop是一个把关系型数据库数据抽向hadoop的工具.同时,也支持将hive.pig等查询的结果导入关系型数据库中存储.由于,笔者部署的hadoop版本是2.2.0,所以sqoop的版本是:sqo ...

  5. uva 10670 Work Reduction(贪心)

    题目连接:10670 - Work Reduction 题目大意:有tol的工作量,和要求达到的工作剩余量sur,然后是公司总数,对应每个公司提供两种服务,1.完成一个工作量,2.完成当前未完成工作量 ...

  6. 虚拟机Linux下一直获取不到ip怎么办

    虚拟机Linux下一直获取不到ip怎么办 Ifconfig -a 只显示了本地的ip127.0.0.1 和另一个eth1 但是找不到ip地址. 需要做的是: 申请ipdhclient eth1 另外释 ...

  7. filezilla

    中文网站:https://www.filezilla.cn/ 英文网站:https://filezilla-project.org/ FileZilla 客户端是一个快速可靠的.跨平台的FTP,FTP ...

  8. SettingsEditplus

      迁移时间:2017年5月20日10:51:51Author:Marydon官网下载 http://www.editplus.com/设置一 1.修改字体大小及背景色 首选项-->Genera ...

  9. 【VMware】宿主机连接wifi,虚拟机中的Linux系统配置连接wifi

    环境描述 宿主机:Windows 10 64bit 虚拟机:Centos 第一步:虚拟机设置 选择连接方式为NAT 第二步:设置宿主机的wifi 控制面板>>网络和Internet> ...

  10. openGL 坐标系的互相转换

    openGL坐标系包括旋转,平移,缩放被塞在一个矩阵里面. 坐标系之间的转换基础是矩阵的运算. 每个矩阵代表的坐标系,就是是原点坐标系通过旋转.平移,缩放得到的坐标系. 当一个矩阵右乘一个向量或是还有 ...