在MATLAB中建模HSV色彩空间 [英] Modeling HSV Color Space in MATLAB

查看:1717
本文介绍了在MATLAB中建模HSV色彩空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在MATLAB中创建一个3D锥,但是:有谁知道如何绘制锥形,以便它重现HSV色彩空间?我知道有命令:



colormap hsv;



但是如何使用? >

提前感谢。

解决方案

我猜你想创建一个情节类似于以下表面带有HSV颜色空间的图像。

 %#首先,创建一个100x100的图像来纹理锥体:

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)]。 %'
hsvImage = cat(3,H,S,V); %#创建HSV映像
C = hsv2rgb(hsvImage); %#将其转换为RGB图像

%#接下来,创建锥形表面坐标:

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

%#最后绘制纹理映射表面:

surf(X,Y,Z,C,'FaceColor','texturemap','EdgeColor'没有');
轴等于

您应该得到下图:




I am able to create a 3D cone in MATLAB, but: does anyone know how to paint the cone so that it recreates the HSV color space? I know there is the command:

colormap hsv;

but how do I use it?

Thanks in advance.

解决方案

I'm guessing you want to create a plot similar to the cone in the following Wikipedia image:

One way to do this is to plot your cone and texture map the surface with an image of the HSV color space. Here's how you could do this:

%# 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

And you should get the following figure:

这篇关于在MATLAB中建模HSV色彩空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆