OpenCV – Convert HSV image to grayscale with hue or saturation channel

A lot of interesting operations with OpenCV start by converting to grayscale. As an interesting experiment, you can convert to HSV first, and display the “grayscale” of one of these channels. It doesn’t make sense to compare the hue between two images (this assumes a specific linearity of images), but it’s an interesting experiment nonetheless:

hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
(h,s,v) = cv2.split(hsv)
v[:] = 100
img = cv2.merge((v, v, s))
rgb = cv2.cvtColor(img, cv2.COLOR_HSV2RGB)	
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)	
cv2.imshow("img", img)
cv2.imshow("rgb", rgb)
cv2.imshow("gray", gray)

For better techniques for grayscale conversion, check out this post which documents a lot of options.

Interested in Python? I send out weekly, personalized emails with articles and conference talks. Click here to see an example and subscribe.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *