• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Matlab图形调色

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Matlab图形调色

 

 

Simple example

var colormap require('colormap')
options {
  colormap'jet',   // pick a builtin colormap or add your own 
  nshades72,       // how many divisions 
  format'hex',     // "hex" or "rgb" or "rgbaString" 
  alpha1           // 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 (colormapnameheight{
    /*
     * 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, height1040);
 
    }
    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(img0, i*40480240);
 
    // 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[01]
        });
        drawColorMaps(colormap, colormaps[i' with transparency', height);
    }
}

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
DELPHI程序的自动升级功能的实现(AUTOUPDATE使用指南)发布时间:2022-07-18
下一篇:
用Delphi 压缩Access数据库发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap