zoukankan      html  css  js  c++  java
  • Matlab获取colorbar颜色并转换为需要的CPT文件

    问题:如何把图片的colorbar颜色转换为需要的CPT文件

    参考Matlab获取文献中的colorbar

    http://bbs.06climate.com/forum.php?mod=viewthread&tid=19108&extra=page%3D1

    http://soliton.vm.bytemark.co.uk/pub/cpt-city/

    http://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml#White-in-the-middle

    解决:

    1)将colorbar截图存储成jpgpng格式文件。

    2Matlab中:
    imread('colorRead.jpg');   %
    得到了一个23*189*3的矩阵,其中
    23是宽(高),189是长,3RGB的维数
    color=ans(11,:,:);    %  
    得到中间一条的颜色信息
    colorfinal=reshape(color,189,3);   %  
    最后得到中间一条每个点的RGB
    colormap(double(colorfinal)/255)    %  
    需要转化成双精度,0-1之间的数值

    colorbar

    ====================

    我的代码

    imread('gravitycolor.png');

    color=ans(2,:,:);%要按实际选择这个信息,因为有时候截取的图片中有混合其他不好看的黑色横线。

    colorfinal=reshape(color,384,3);

    colormap(double(colorfinal)/255)

    colorbar

    colormap;

    (3)将得到的colormap中的rgb[0,1]数值转换为255进制;并参考gmt中cpt的格式进行格式变换。

    grav=colormap*255;

    gr1=grav(1:2:end,1:3);

    gr2=grav(2:2:end,1:3);

    x=[-382:4:382];x=x';

    y=[-378:4:386];y=y';

    g=[x gr1 y gr2];

    g矩阵复制参考其他cpt格式保存成mygrav.cpt

    mygrav.cpt末尾加上

    B    0 0 0

    F    255 255 255

    N    128 128 128

    (4gmt画图

    ===========================gmt默认的cpt格式

    # $Id: globe.cpt 12822 2014-01-31 23:39:56Z remko $

    -10000    153/0/255    -9500    153/0/255

    -9500    153/0/255    -9000    153/0/255

    -9000    153/0/255    -8500    153/0/255

    -8500    136/17/255    -8000    136/17/255

    或者

    #    $Id: GMT_no_green.cpt,v 1.1.1.1 2000/12/28 01:23:45 gmt Exp $

    # Colormap using in Lab for Satellite Altimetry

    # For folks who hate green in their cpt files

    # Designed by W.H.F. Smith, NOAA

    # COLOR_MODEL = RGB

    -32    32    96    255    -28    32    96    255

    -28    32    159    255    -24    32    159    255

    -24    32    191    255    -20    32    191    255

    -20    0    207    255    -16    0    207    255

    另外

    刚知道的,备忘

    https://cn.mathworks.com/matlabcentral/fileexchange/28943-color-palette-tables---cpt--for-matlab

    https://github.com/kakearney/cptcmap-pkg

  • 相关阅读:
    每日签到
    手机刮刮卡
    js随机更换
    jquery实现input输入框实时输入触发事件代码
    webAPP前端必备知识
    让你分分钟学会 JS 闭包
    js获取url?后的参数
    js获取上传的文件名
    Javascript 中神奇的 this
    由浅入深完全掌握Ajax
  • 原文地址:https://www.cnblogs.com/gisalameda/p/7890915.html
Copyright © 2011-2022 走看看