绘制色调的单色

Drawing monochromatic colors of a hue

基于 wiki page,单色是单一色调的所有颜色(色调、色调和阴影)。还显示了 'red' 的单色示例。我想知道是否有任何方法可以在 MATLAB 中为任何色调(如红色、绿色、蓝色)生成它?

。然而,准确的答案取决于您如何绘制 "figure".

colormap 是您想要的函数,以防您有曲面图。

color, markerfacecolor,markeredgecolor 是用于绘制线条和标记的属性。

image 是处理图像时的函数。它是一个具有 RGB 值的数组。

在所有情况下,颜色由 [r g b] 指定,但对于颜色图和图像,它们是一个矩阵,分别包含每个步骤或像素的所有值。按照带有曲面图和自定义 colormap.

的示例
[x,y]=meshgrid(1:10,1:10);
surface(x,y) %this will give a 'plane', but with the default color. 
%creating a proper colormap from white to red
r=ones(10,1); %always red
g=linspace(0,1,10); %linear increase
b=g; %copy green to blue
redmap=[r g' b'];
colormap(redmap)

给出这张图:

请注意,我使用 10 点制作了 RGB 比例尺,您可以根据需要制作它,只要您有完整的红色(始终为 1),绿色和蓝色线性增加并且所有值都相同时间。 [1 1 1] 是白色,[1 0 0] 是红色,[0 1 0] 是绿色,[0 0 0] 是黑色。您可以在 colormap manual 的其中一个部分中检查其他颜色。

您可以通过更改颜色的 alpha 值(同时保持 RGB 值不变)来获得此效果。

这是一个使用半透明多边形的小演示:

function q48731598(drawBG)
%% Handling inputs:
if nargin < 1
  drawBG = true;
end
%% Constants:
LEVELS = 10;
%% User input:
c = uisetcolor([1 1 0], 'Select a color');
%% The rest...
alph = linspace(0.1, 1, LEVELS);

bg = checkerboard(8,30); % default background
sz = size(bg);
if ~drawBG
  bg = ones(sz); % create a white background of the same size
end

figure(); imshow(bg); hold on;

for ind1 = 1:LEVELS % create several polygons:
  patch([1, sz(1) sz(1) 1], ...
        [1+(ind1-1)*sz(2)/LEVELS*[1 1] (1+(ind1-0)*sz(2)/LEVELS-1)*[1 1]],...
        c, 'FaceAlpha', alph(ind1));
end 

如果您运行喜欢q48731598(false)并选择红色,您将获得:

checkerboard 背景可见时:

感谢@Guto 的想法。这是我绘制单色红色的 MATLAB 代码。

之前的两个答案都绘制了 tints 红色。单色是指一种色调的全光谱。换句话说,单色是单一色调的所有颜色(色调、色调和阴影)。

h = zeros(10,1); % red
steps = 20;

% tints (reducing saturation while value is constant in HSV)
s = linspace(1,0.1,10); % stop S at 0.1
v = ones(10,1);
hsv_colormap_tints = [h s' v];

% shades (reducing value while saturation is constant in HSV)
s = ones(10,1);
v = linspace(1,0.1,10); % stop V at 0.1
hsv_colormap_shades = [h s v'];

% remove the first row
hsv_colormap_tints = hsv_colormap_tints(2:end,:);
% and then flip
hsv_colormap_tints = flipud(hsv_colormap_tints);
% appending two color maps
hsv_colormap = [hsv_colormap_tints' hsv_colormap_shades']';
% convert to RGB model
rgb_colormap = hsv2rgb(hsv_colormap);

ax = figure(1);
colormap(ax, rgb_colormap);

[x,y] = meshgrid(1:steps,1:steps);
h = surface(x,y');
set(h,'edgecolor','none');
title('Monochromatic colors of red', 'FontSize', 20);
% hide both axis
set(gca,'xtick',[]);
set(gca,'ytick',[]);

要在@Guto asnwer 上构建,在 matlab 中您可以直接使用 hsv2rgb() 函数。这样,您可以确定您只是在更改恒定色调的饱和度和值。 这是一个例子:

figure
N = 10;
[x,y]=meshgrid(0:N,0:N);
surface(x,y) %this will give a 'plane', but with the default color. 
%creating a proper colormap from white to red
h = zeros(N,1) + 1;     % Constant hue = 100%
s = linspace(1,0,N)';   % Variable saturation
v = zeros(N,1) + 1;     % Constant value
rgb = hsv2rgb([h,s,v]);
colormap(rgb)

稍作修改,即可绘制色调:

figure
N = 30;
[x,y]=meshgrid(0:N,0:N);
surface(x,y)
h = linspace(1,0,N)';   % Sweep hused
s = h.*0 + 1;
v = s;
colormap(hsv2rgb([h,s,v]))