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.
HSV — HSV imageValue from 0 to 1 that corresponds to the color's position on a color wheel. As hue increases from 0 to 1 , the color transitions from red to orange, yellow, green, cyan, blue, magenta, and finally back to red. Saturation. Amount of hue or departure from neutral.
RGB = hsv2rgb( HSV ) converts the hue, saturation, and value (HSV) values of an HSV image to red, green, and blue values of an RGB image. rgbmap = hsv2rgb( hsvmap ) converts an HSV colormap to an RGB colormap.
The advantage of HSV is that it generalizes how humans perceive color. Hence it is the most accurate depiction of how we feel colors on the computer screen. Also, the HSV color space separates the luma from the color information.
Convert RGB Image to HSV Image Convert the image to the HSV color space. HSV = rgb2hsv(RGB); Process the HSV image. This example increases the saturation of the image by multiplying the S channel by a scale factor.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With