Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to obtain a single channel value image from HSV image in opencv 2.1?

I am a beginner in opencv. I am using opencv v2.1. I have converted an RGB image to HSV image. Now I want to obtain single channels Hue, Value and Saturation separately. What should I do? I have seen similar questions here but No-one answered that. Kindly help.

like image 997
userXktape Avatar asked Jun 19 '13 07:06

userXktape


1 Answers

Solution for Python:

import cv2
from matplotlib import pyplot as plt

# Read image in BGR
img_path = "test.jpg"
img = cv2.imread(img_path)

# Convert BGR to HSV and parse HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = hsv_img[:, :, 0], hsv_img[:, :, 1], hsv_img[:, :, 2]

# Plot result images
plt.imshow("Original", cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.imshow("HSV", hsv_img)
plt.imshow("H", h)
plt.imshow("S", s)
plt.imshow("V", v)
plt.show()
like image 91
Leonid Dashko Avatar answered Oct 12 '22 23:10

Leonid Dashko