0

我必须创建一个地图来显示某些值与某个范围的距离有多近,并因此为它们提供颜色。同时,该范围内的值应具有另一种不同的颜色。
例如:只有在 [-2 2] 范围内的结果才被认为是有效的。对于其他值,颜色必须显示与这些限制的距离(-3 比 -5 亮,更暗)
我已经尝试使用颜色条, 但我无法设置自定义色标。
任何想法??提前致谢!

4

2 回答 2

0

下面是我刚刚汇总的一些代码,用于演示创建您自己的查找表并将值分配给您正在使用的图像的简单方法。我假设你的结果是一个二维数组,我只是使用随机分配的值,但概念是一样的。

我提到了将 HSV 用作着色方案的潜在用途。请注意,这要求您拥有 am by n x 3 矩阵。顶层是 H - 色调,第二层是 S - 饱和度,第三层是 V 或值(明/暗)。只需将 H 和 S 设置为您想要的颜色值,并以类似的方式改变 V,如下所示,您可以获得所需的各种浅色和深色。

% This is just assuming a -10:10 range and randomly generating the values.
randmat = randi(20, 100);
randmat = randmat - 10;

% This should just be a black and white image.  Black is negative and white is positive.
figure, imshow(randmat) 

% Create your lookup table.  This will illustrate having a non-uniform
% acceptable range, for funsies.
vMin = -3;
vMax = 2;

% I'm adding 10 here to account for the negative values since matlab
% doesn't like the negative indicies...
map = zeros(1,20); % initialized
map(vMin+10:vMax+10) = 1; % This will give the light color you want.

%linspace just simply returns a linearly spaced vector between the values
%you give it.  The third term is just telling it how many values to return.
map(1:vMin+10) = linspace(0,1,length(map(1:vMin+10)));
map(vMax+10:end) = linspace(1,0,length(map(vMax+10:end))); 

% The idea here is to incriment through each position in your results and
% assign the appropriate colorvalue from the map for visualization.  You
% can certainly save it to a new matrix if you want to preserve the
% results!
for X = 1:size(randmat,1)
    for Y = 1:size(randmat,2)
        randmat(X,Y) = map(randmat(X,Y)+10);
    end
end

figure, imshow(randmat)
于 2012-06-27T17:09:52.830 回答
0

您需要为您拥有的值范围定义一个颜色图。
颜色图是 N*3 矩阵,定义了每种颜色的 RGB 值。

有关范围 -10:10 和有效值 v1、v2 的信息,请参见下面的示例:

v1=-3;  
v2=+3;  
a = -10:10;  
graylevels=[...  
   linspace(0,1,abs(-10-v1)+1) , ...
   ones(1, v2-v1-1) , ...
   linspace(1,0,abs(10-v2)+1)];  
c=repmat(graylevels , [3 1])';  
figure;  
imagesc(a);  
colormap(c);
于 2012-06-27T16:18:57.330 回答