Search code examples
pythonopencvrgbhsv

Show Images that are coded with HSV in real colors with PIL or Opencv


I have converted an image with opencv to hsv with the code:

hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

Now I look at the Image with PIL using

Image.fromarray(np.asarray(hsv_img,dtype=np.uint8))

The now showed image is now the interpretation of the HSV values as RGBs. Is it possible to display the Image from the HSV color spectrum interpreted as HSV and not as RGBs without changing it back to RGB


Solution

  • Change this line:

    Image.fromarray(np.asarray(hsv_img,dtype=np.uint8))
    

    to include mode, so:

    Image.fromarray(np.asarray(hsv_img ,dtype=np.uint8), 'HSV')
    

    PIL's show() method should then display that correctly.