Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting image from RGB to HSV color space

Tags:

I couldn't find such function (i.e. RGB_to_HSV()) in Scipy or Matplotlib's documentations, and Google doesn't show pointers, except ActiveState recipe which demonstrates rgb2hsv function, though not usable on Numpy array as is.

Does someone know of a shortcut?


Edit: Sorry, just found matplotlib.colors.rgb_to_hsv() which is exactly what I was looking for. Should I delete this question?

like image 837
theta Avatar asked Mar 07 '13 17:03

theta


People also ask

Why image is converted from RGB to HSV?

R, G, B in RGB are all co-related to the color luminance( what we loosely call intensity),i.e., We cannot separate color information from luminance. HSV or Hue Saturation Value is used to separate image luminance from color information. This makes it easier when we are working on or need luminance of the image/frame.

How do I convert RGB image to HSV in Opencv?

To choose the correct code, we need to take in consideration that, when calling the imread function, the image will be stored in BGR format. Thus, to convert to HSV, we should use the COLOR_BGR2HSV code. As output, the cvtColor will return the converted image, which we will store in a variable.

How do I convert a RGB image to grayscale?

You just have to take the average of three colors. Since its an RGB image, so it means that you have add r with g with b and then divide it by 3 to get your desired grayscale image. Its done in this way.


1 Answers

Matplotlib provides RGB to HSV conversion function: matplotlib.colors.rgb_to_hsv():

matplotlib.colors.rgb_to_hsv(arr)

convert rgb values in a numpy array to hsv values input and output arrays should have shape (M,N,3)

like image 164
theta Avatar answered Oct 06 '22 01:10

theta