I'm trying to split a HSV image into its channels, change them and them merge them back, however once I run the merge function the channels are interpreted as RBG channels, so for example for the following example I get a yellow image,
import cv2
image = cv2.imread('example.jpg')
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_image)
s.fill(255)
v.fill(255)
hsv_image = cv2.merge([h, s, v])
cv2.imshow('example', hsv_image)
cv2.waitKey()
What is the proper way to do this in OpenCV 3 using Python?
Images are always displayed as they are BGR. If you want to show your HSV image, you need to convert to BGR first:
import cv2
image = cv2.imread('example.jpg')
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_image)
s.fill(255)
v.fill(255)
hsv_image = cv2.merge([h, s, v])
out = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR)
cv2.imshow('example', out)
cv2.waitKey()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.