在MATLAB中建模HSV颜色空间

时间:2010-07-26 23:22:53

标签: matlab colors computer-vision hsv

我能够在MATLAB中创建一个3D圆锥体,但是:有没有人知道如何绘制圆锥以便重新创建HSV颜色空间?我知道有命令:

colormap hsv;

但我该如何使用它?

提前致谢。

1 个答案:

答案 0 :(得分:12)

我猜你想在下面的Wikipedia图像中创建一个类似于圆锥的图:

执行此操作的一种方法是使用HSV颜色空间的图像绘制锥体和texture map曲面。这是你如何做到这一点:

% First, create a 100-by-100 image to texture the cone with:

H = repmat(linspace(0, 1, 100), 100, 1);     % 100-by-100 hues
S = repmat([linspace(0, 1, 50) ...           % 100-by-100 saturations
            linspace(1, 0, 50)].', 1, 100);  %'
V = repmat([ones(1, 50) ...                  % 100-by-100 values
            linspace(1, 0, 50)].', 1, 100);  %'
hsvImage = cat(3, H, S, V);                  % Create an HSV image
C = hsv2rgb(hsvImage);                       % Convert it to an RGB image

% Next, create the conical surface coordinates:

theta = linspace(0, 2*pi, 100);  % Angular points
X = [zeros(1, 100); ...          % X coordinates
     cos(theta); ...
     zeros(1, 100)];
Y = [zeros(1, 100); ...          % Y coordinates
     sin(theta); ...
     zeros(1, 100)];
Z = [2.*ones(2, 100); ...        % Z coordinates
     zeros(1, 100)];

% Finally, plot the texture-mapped surface:

surf(X, Y, Z, C, 'FaceColor', 'texturemap', 'EdgeColor', 'none');
axis equal

你应该得到下图:

enter image description here