matlab中image和matlab colormap函数是什么关系

matlab 的色图函数colormap 详解_矩阵_中国百科网
matlab 的色图函数colormap 详解
    该文章讲述了matlab 的色图函数colormap 详解.
matlab中,每个figure都有(而且仅有)一个colormap,翻译过来就是色图。
COLORMAP(MAP) 用MAP矩阵映射当前图形的色图。
COLORMAP('default') 默认的设置是 JET.
MAP = COLORMAP 获得当前色图矩阵.
COLORMAP(AX,...) 应用色图到AX坐标对应的图形,而非当前图形。
MAP实际上是一个mx3的矩阵,每一行的3个值都为0-1之间数,分别代表颜色组成的rgb值,
[1 0 0] 代表红色,[0 1 0]代表绿色,[0 0 1]代表蓝色。系统自带了一些colormap,如:winter、autumn等。输入winter,就可以看到它是一个64x3的矩阵。用户可以自定义自己的colormap,而且不一定是64维的。
[0 0 0] is black, [1 1 1] is white,
[1 0 0] is pure red, [.5 .5 .5] is gray, and
[127/255 1 212/255] is aquamarine.
那么颜色在fill或patch,SURFACE等函数中到底是如何显示的呢?本质上,是把具体的颜色变成colormap中的相应index,也就是行数。这个过程叫做换算映射:将指定的数值颜色向量(矩阵)C,映射到对应的颜色。颜色矩阵C的数值范围为[Cmin, Cmax], Cmin 和Cmax的数值或者为
min(min(C)) max(max(C)),也可以在CAXIS中设置。
在matlab中,图形窗的属性'CdataMapping&缺省设置值为'scaled',也就是线性的映射。
Cmin对应的值映射到colormap的第一行,Cmax对应的值映射到colormap的最后一行。
映射过程如下:
首先,需要根据caxis取得Cmin和Cmax两个变量(默认值为0和1),画图时如果指定了数值颜色向量(矩阵)C,Cmin和Cmax自动设置为C中的最大值和最小值。当你想控制时,可以自定义。比如将Cmax减小,这样将把所有大于Cmax的C值,全部都映射到同一个颜色(colormap 中index最大的行代表的颜色)。
根据Cij在Cmin和Cmax之间的比例关系,确定对应的颜色的index,默认为线性映射。
也就是说,当制定了数值颜色向量(矩阵)C之后画图,图中颜色的使用范围会自动占满整个颜色范围!该文章讲述了matlab 的色图函数colormap 详解(2).
matlab 的色图函数colormap实例:
x=[0 1 1 0];
y=[0 0 1 1]; %定义四个点 [0 0] [1 0] [1 1] [0 1]
H_F=fill(x,y,[0 0.1 0.2 0.6]); %定义四个点的C值
row_cmap = 15; %定义色图矩阵的行数
color_map1=zeros(row_cmap,3); %定义色图矩阵
color_r = 0:1/(row_cmap-1):1;
color_g = 0:1/(row_cmap-1):1;
color_b = 0:1/(row_cmap-1):1;
color_map1(:,1) = color_r;
color_map1(:,2) = color_g;
colormap(color_map1);
%本例中颜色从[0 0 0] 变化到[1 1 0]
%增加row_cmap的值,如变化到100,则可看到颜色的渐变,而非跳跃型变化。
Copyright by ;All rights reserved.MATLAB: Show colorbar of a grayscale image in a figure containing a RGB image - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
Suppose we have two images:
1) RGB Image:
% initialize RGB image:
rgbIm = zeros(100, 100, 3);
rgbIm(20:80, 20:80, 1) = 1;
2) Grayscale Image:
% initialize grayscale image:
grayIm = zeros(100);
grayIm(20:80, 20:80) = 1;
Lets show both of them:
figure, imshow(rgbIm),
colormap('jet'),
figure, imshow(grayIm), colormap('jet'),
As we can see, the colorbar in the 2nd figure (i.e. grayscale image) makes total sense. On the other hand I can't really understand the information given by the colormap in the 1st figure.
What I would like to achieve is to display the colorbar of the grayscale image in the figure corresponding to the RGB image.
It might seem that this does not make sense but this is just a very minimal example that I just made up to show what I would like to do in a larger project.
Any thoughts?
Thanks a lot :)
EDIT1: Allow me to explain why I would need this
Suppose I compute some physiological parameters one MRI slice in certain regions of interest, yielding something like this:
Now I want to superimpose these parameters on top of the original slice, and I create one RGB image to achieve this:
The colormap does not make sense, and this is why I would like to display the colormap corresponding to the parametric image in the RGB image (i.e. the superimposition image).
Any ideas?
Thank you for your attention.
I still think what you are asking does not make sense.
Let me explain:
What is colorbar? Colorbar is a representation of a function (mapping) from gray-level (scalar) to color. Using jet, in your example, you map the 0 to dark blue and 1 to red.
By asking for a colorbar for an RGB image, you are actually asking for a mapping from RGB triplet to RGB color -- this mapping is the identity mapping! you do not need a colorbar to see this mapping, each pixel represent it!
After seeing the edited question, I revise my answer a bit:
Since both MRI signal and whatever physiological parameters you computed makes no sense in RGB space, you have two 1D mappings:
1. MRI signal at each voxel to gray level ("gray" colormap)
2. Physiological measure at each voxel to "jet" color
What I usually do in this cases is convert the 2D MRI slice into RGB gray image by simply replicate it along the third dimension
rgbSlice = twoDSlice(:,:,[1 1 1]);
Now show the images on top of each other
imshow( rgbSlice );
h = imshow( physiologicalParams );
set(h, 'AlphaData', .5 );
You might need to play with the color mapping of the axes using caxis or clim to get it right.
41.9k1560129
(Answering my own question so I can hopefully help someone in the future)
I just accomplished what I intended, with the help of the above
and a post from .
Here's how:
baseImage = baseImage/(max(baseImage(:))); % normalize base (anatomical) image
= baseImage(:,:,[1 1 1]);
% converting to RGB (ignore colormaps)
imshow(parameterROIImage, []);
% show parametric image
colormap('jet');
% apply colormap
h = imshow(rgbSlice);
% superimpose anatomical image
set(h, 'AlphaData', ~bwROIlocations);
% make pixels in the ROI transparent
where parameterROIImage is:
bwROIlocations is the logical matrix containing the ROI pixels:
Final result:
Thanks for the help Shai.
41.9k1560129
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled[转载]matlab的colormap的保存
很多人在用colormapeditor得到了自定义的colormap后想保存下来再次应用,如何保存并再次利用?大家可以自己help
colormapeditor,如果英文看不明白,可以看看博主写的小例子。
xa=-2:0.2:2;ya=
[x,y]=meshgrid(xa,ya);
z=x.*exp(-x.^2-y.^2);
contourf(x,y,z);title('原始图像')
博主很不喜欢这个colormap,于是在command window输入colormapeditor,修改了一下,效果如下
如果你不是色盲的话就应该能看出区别,接下来保存自定义的colormap,
mycmap = get(gcf,'Colormap')%gcf是get current figure的缩写
我们可以看到WORKSPACE里多了mycmap。
save('MyColormaps','mycmap')%把mycmap变量保存为MyColormaps.mat,位置在matlab当前目录
你下次画图的时候还想用的话只要将MyColormaps.mat加载进来,画图,然后来一句:colormap(mycmap),就OK了。
保存colormap还可以利用句柄,程序如下
%先把之前的图片窗口给关了
fig=figure();%打开一个空白的图片窗口,fig为句柄(figure handle)
contourf(x,y,z);
get(fig,'Colormap');%我们可以看到工作区间保存了画图默认的colormap,名为mycmap2
不过我更喜欢用下面的方法,程序如下,
figure(2)
contourf(x,y,z);%画出来的就是默认的colormap,也就是之前保存的mycmap2,
set(2,'Colormap',mycmap)%2就是句柄,设定figure2使用的colormap为自定义的mycmap
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。下次自动登录
现在的位置:
& 综合 & 正文
MATLAB中图像函数大全
Matlab中图像函数大全 2
&&&&推荐文章:
【上篇】【下篇】二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(952)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'Matlab 画图色彩 Vivid Colormap',
blogAbstract:'\r\n\r\n\r\n\r\n\r\nmatlab里的漂亮配色方案,收藏学习\r\n以下内容来自Matlab Central\r\n
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 matlab中的colormap 的文章

 

随机推荐