【问题标题】:Creating my own colormap, such that two different colors can be plotted on one image in Matlab创建我自己的颜色图,这样可以在 Matlab 中的一张图像上绘制两种不同的颜色
【发布时间】:2014-07-24 22:19:45
【问题描述】:

我想让较亮的像素以绿色显示,而不亮的特征以蓝色显示。这是我尝试过的

for i=1:128
mycolormap(64:128,2)=i/128;
mycolormap(1:63,3)=i/128;
mycolormap(1:63,2)=0;
mycolormap(64:128,3)=0;
mycolormap(i,1)=0;
end

我正在使用 Uint16 .tif 的图像 在实例化之前,我考虑过将颜色图转换为双精度图。 谢谢!

阅读您添加的评论内容确实有助于我思考问题,因此我调整了我的代码并通过一些廉价的编码得到了我想要的东西。但现在我得到了我想要的谢谢!

     for i=1:128                  % start a loop (see comment above about i variable)
                             % then in EACH iteration
mycolormap(i,2)=i/128;  % fill bottom half of 2nd column of MYCOLORMAP with i/128
mycolormap(i:63,3)=i/128;    % fill top    half of 3rd column of MYCOLORMAP with i/128
mycolormap(1:63,2)=0;        % fill top    half of 2nd column of MYCOLORMAP with 0
mycolormap(64:128,3)=0;      % fill bottom half of 3rd column of MYCOLORMAP with 0
mycolormap(i,1)=0;           % fill i-th   row  of 1st column with 0
end
>> mycolormap

mycolormap =

         0         0    0.0078
         0         0    0.0156
         0         0    0.0234
         0         0    0.0313
         0         0    0.0391
         0         0    0.0469
         0         0    0.0547
         0         0    0.0625
         0         0    0.0703
         0         0    0.0781
         0         0    0.0859
         0         0    0.0938
         0         0    0.1016
         0         0    0.1094
         0         0    0.1172
         0         0    0.1250
         0         0    0.1328
         0         0    0.1406
         0         0    0.1484
         0         0    0.1563
         0         0    0.1641
         0         0    0.1719
         0         0    0.1797
         0         0    0.1875
         0         0    0.1953
         0         0    0.2031
         0         0    0.2109
         0         0    0.2188
         0         0    0.2266
         0         0    0.2344
         0         0    0.2422
         0         0    0.2500
         0         0    0.2578
         0         0    0.2656
         0         0    0.2734
         0         0    0.2813
         0         0    0.2891
         0         0    0.2969
         0         0    0.3047
         0         0    0.3125
         0         0    0.3203
         0         0    0.3281
         0         0    0.3359
         0         0    0.3438
         0         0    0.3516
         0         0    0.3594
         0         0    0.3672
         0         0    0.3750
         0         0    0.3828
         0         0    0.3906
         0         0    0.3984
         0         0    0.4063
         0         0    0.4141
         0         0    0.4219
         0         0    0.4297
         0         0    0.4375
         0         0    0.4453
         0         0    0.4531
         0         0    0.4609
         0         0    0.4688
         0         0    0.4766
         0         0    0.4844
         0         0    0.4922
         0    0.5000         0
         0    0.5078         0
         0    0.5156         0
         0    0.5234         0
         0    0.5313         0
         0    0.5391         0
         0    0.5469         0
         0    0.5547         0
         0    0.5625         0
         0    0.5703         0
         0    0.5781         0
         0    0.5859         0
         0    0.5938         0
         0    0.6016         0
         0    0.6094         0
         0    0.6172         0
         0    0.6250         0
         0    0.6328         0
         0    0.6406         0
         0    0.6484         0
         0    0.6563         0
         0    0.6641         0
         0    0.6719         0
         0    0.6797         0
         0    0.6875         0
         0    0.6953         0
         0    0.7031         0
         0    0.7109         0
         0    0.7188         0
         0    0.7266         0
         0    0.7344         0
         0    0.7422         0
         0    0.7500         0
         0    0.7578         0
         0    0.7656         0
         0    0.7734         0
         0    0.7813         0
         0    0.7891         0
         0    0.7969         0
         0    0.8047         0
         0    0.8125         0
         0    0.8203         0
         0    0.8281         0
         0    0.8359         0
         0    0.8438         0
         0    0.8516         0
         0    0.8594         0
         0    0.8672         0
         0    0.8750         0
         0    0.8828         0
         0    0.8906         0
         0    0.8984         0
         0    0.9063         0
         0    0.9141         0
         0    0.9219         0
         0    0.9297         0
         0    0.9375         0
         0    0.9453         0
         0    0.9531         0
         0    0.9609         0
         0    0.9688         0
         0    0.9766         0
         0    0.9844         0
         0    0.9922         0
         0    1.0000         0

【问题讨论】:

标签: matlab colormap


【解决方案1】:

您的代码看起来有些奇怪:

for i=1:128                  % start a loop (see comment above about i variable)
                             % then in EACH iteration
mycolormap(64:128,2)=i/128;  % fill bottom half of 2nd column of MYCOLORMAP with i/128
mycolormap(1:63,3)=i/128;    % fill top    half of 3rd column of MYCOLORMAP with i/128
mycolormap(1:63,2)=0;        % fill top    half of 2nd column of MYCOLORMAP with 0
mycolormap(64:128,3)=0;      % fill bottom half of 3rd column of MYCOLORMAP with 0
mycolormap(i,1)=0;           % fill i-th   row  of 1st column with 0
end

所以,在你的循环之后
- MYCOLORMAP 的第 2 列的下半部分用 1 填充
- MYCOLORMAP 第 3 列的上半部分用 1 填充。

这是因为在您的循环中,您使用不同的值填充颜色图的完全相同的元素,因此只有最后一个带有 i=128 的元素仍然存在。

通过以下方式更容易实现此结果:

mycolormap = zeros(128,3);
mycolormap(64:128,2)=1;
mycolormap(1:63,3)=1;

但是,如果这不是您期望的颜色图,请详细说明您需要什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-05
    • 2019-02-22
    • 2016-05-30
    • 2020-03-08
    • 2013-09-17
    相关资源
    最近更新 更多