Convert Colors from RGB to HSV in R Programming – rgb2hsv() Function

rgb2hsv() function in R Language is used to transform colors from RGB space(red / green / blue) into HSV space(hue / saturation / value).

Syntax: rgb2hsv(r, g, b)

Parameters:
r: vector of ‘red’ values.
g: vector of ‘green’ values, or NULL when r is a matrix.
b: vector of ‘blue’ values, or NULL when r is a matrix.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# rgb2hsv function
  
# Calling the col2rgb() function to
# get color in rgb
rgb = col2rgb("# 08a0ff")
  
# Calling the rgb2hsv() function to
# convert the RGB values in the 
# colormap to HSV
rgb2hsv(rgb)

chevron_right


Output:

       [, 1]
h 0.5641026
s 0.9686275
v 1.0000000

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# rgb2hsv function
  
# Calling the rgb2hsv() function
rgb2hsv(60, 120, 180)

chevron_right


Output:

       [, 1]
h 0.5833333
s 0.6666667
v 0.7058824
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.