码迷,mamicode.com
首页 > 其他好文 > 详细

Matlab获取colorbar颜色并转换为需要的CPT文件

时间:2017-11-24 17:06:18      阅读:967      评论:0      收藏:0      [点我收藏+]

标签:横线   矩阵   shape   文件   byte   end   city   style   hit   

问题:如何把图片的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

3gmt画图

===========================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

Matlab获取colorbar颜色并转换为需要的CPT文件

标签:横线   矩阵   shape   文件   byte   end   city   style   hit   

原文地址:http://www.cnblogs.com/gisalameda/p/7890915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!