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?
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.
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.
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.
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)
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