Here's an example of how to use the rgb2hsv
function in MATLAB to convert an RGB image to HSV and display the H, S, and V channels separately:
main.m363 chars17 lines
The imread
function is used to load an example RGB image (peppers.png
). The imshow
function is then used to display the RGB image.
The rgb2hsv
function is used to convert the RGB image to HSV. This results in an image with three channels: H (hue), S (saturation), and V (value).
The hsv(:,:,1)
, hsv(:,:,2)
, and hsv(:,:,3)
commands are used to extract the H, S, and V channels from the HSV image, respectively.
Finally, the subplot
function is used to display each of the channels separately in a new figure window. The first argument to subplot
specifies the number of rows and columns of subplots in the figure, and the second argument specifies which subplot to display. The title
function is used to add titles to each subplot.
gistlibby LogSnag