Search code examples
pythonnumpyimage-processingpython-imaging-librarycolor-channel

Extract hue channel from HSV image in Pillow


I'm trying to extract the hue channel from a pillow image. Below is an illustration:

In [40]: from PIL import Image
In [41]: pillow_img  = Image.open('lekha.jpg')

# convert to HSV    
In [42]: hsv_img = pillow_img.convert('HSV')

# cast it as NumPy array
In [43]: arr_hsv = np.asarray(hsv_img)

Now, how can I extract only the hue channel from the array arr_hsv?

If it's an RGB image, extracting the red channel would translate to:

red_channel =  arr_rgb[:, :, 0]

However, I'm unsure whether this is the same case for HSV as well.


Solution

  • It's the same.

    hue_channel =  arr_hsv[:, :, 0]