Gary Sieling

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.

Exit mobile version