Merge HSV channels under OpenCV 3 in Python

I try to split the HSV image into its channels, change them and merge them back, however, as soon as 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 correct way to do this in OpenCV 3 using Python?

+5
source share
1 answer

Images are always displayed as BGR. If you want to display your HSV image, you must first convert to BGR:

 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() 
+7
source

Source: https://habr.com/ru/post/1240296/


All Articles