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. Logging with PSR-3 to Improve Reusability

    可以用composer的autoload来,导入自己写的类库.   composer dump-autoload -o  ----------------> 改成 composer update ...

  2. (转)初识 Lucene

    Lucene 是一个基于 Java 的全文信息检索工具包,它不是一个完整的搜索应用程序,而是为你的应用程序提供索引和搜索功能.Lucene 目前是 Apache Jakarta 家族中的一个开源项目. ...

  3. 一直出现 Enter passphrase for key '/root/.ssh/gitkey12.pub'

    案例: 我一下没有设置密码的pub key, 一使用就要求: Enter passphrase for key '/root/.ssh/gitkey12.pub',   原因:本该设置私钥的地方,设置 ...

  4. windows下安装redis 以及phpredis的扩展 (windows redis php&php7)

    一.工具准备 1. redis for windows 下载 https://github.com/MSOpenTech/redis 2. PHP扩展下载 http://pecl.php.net/pa ...

  5. Android 色彩设计理念

    色彩 色彩从当代建筑.路标.人行横道以及运动场馆中获取灵感.由此引发出大胆的颜色表达激活了色彩,与单调乏味的周边环境形成鲜明的对照. 强调大胆的阴影和高光.引出意想不到且充满活力的颜色. 色样 – 0 ...

  6. (LeetCode 153)Find Minimum in Rotated Sorted Array

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  7. hadoop2.2.0_hbase0.96_zookeeper3.4.5全分布式安装文档下载

    本文档主要内容有: 1.hadoop 2.2.0 集群安装与部署 2.HBase 0.96 集群安装与部署 3.Zookeeper 3.4.5集群安装部署 备注:安装文档可能有所遗漏,后续将持续更新. ...

  8. iptables日志与limit参数

    在处理工作问题的时候需要查看防火墙的日志,由于默认日志都是在系统日志里/var/log/messages里面.需要对rsyslog做设置. 首先编辑配置文件/etc/rsyslog.conf如下: # ...

  9. Android入门之简单拨号器

    效果图: package jk.phone; import android.net.Uri; import android.os.Bundle; import android.app.Activity ...

  10. QT内label控件通过opencv显示图像

    1.对pro进行配置.使其可以理解opencv. INCLUDEPATH+=d:\opencv249\include\opencv\ d:\opencv249\include\opencv2\ d:\ ...