Iamnotperfect
Iamnotperfect

Reputation: 119

HSV colorspace conversion between opencv vs skimage

I was comparing the difference between skImage HSV color space and OpenCV hsv colourspace conversion methods, I found the below difference which I didn't understand:

from PIL import Image
from skimage import io
import numpy as np
import cv2

image = PIL.Image.open("112.jpg")
data = np.asarray(image)                      #Feeding the same  RGB array
y1=cv2.cvtColor(np.float32(data),cv2.COLOR_RGB2HSV)
y1 = y1.astype(np.uint8)
y2= color.rgb2hsv(data)                       #skimage conversion

I used PIL to make sure I am feeding RGB array. Here, when I printed the images I got the following outputs.

y1

>>> array([[[ 52,   0, 252],
    [ 52,   0, 252],
    [ 52,   0, 252],
    ...,
    [ 59,   0, 186],
    [ 59,   0, 186],
    [ 59,   0, 186]],

   [[ 52,   0, 252],
    [ 52,   0, 252],
    [ 52,   0, 252],
    ...,
    [ 59,   0, 186],
    [ 59,   0, 186],
    [ 59,   0, 186]],

   [[ 52,   0, 252],
    [ 52,   0, 252],
    [ 52,   0, 252],
    ...,
    [ 59,   0, 187],
    [ 59,   0, 187],
    [ 59,   0, 187]],

   ...,


y2

>>> array([[[0.14465409, 0.21031746, 0.98823529],
    [0.14465409, 0.21031746, 0.98823529],
    [0.14465409, 0.21031746, 0.98823529],
    ...,
    [0.16515152, 0.59139785, 0.72941176],
    [0.16515152, 0.59139785, 0.72941176],
    [0.16515152, 0.59139785, 0.72941176]],

   [[0.14465409, 0.21031746, 0.98823529],
    [0.14465409, 0.21031746, 0.98823529],
    [0.14465409, 0.21031746, 0.98823529],
    ...,
    [0.16515152, 0.59139785, 0.72941176],
    [0.16515152, 0.59139785, 0.72941176],
    [0.16515152, 0.59139785, 0.72941176]],

   [[0.14465409, 0.21031746, 0.98823529],
    [0.14465409, 0.21031746, 0.98823529],
    [0.14465409, 0.21031746, 0.98823529],
    ...,
    [0.16515152, 0.58823529, 0.73333333],
    [0.16515152, 0.58823529, 0.73333333],
    [0.16515152, 0.58823529, 0.73333333]],

   ...,
  1. why are my y1 and y2 arrays different? do skimage and opencv follow different conversion formulas for the same colorspace?

  2. Which is the standard and the most followed way to convert an RGB image to HSV image: "cvtColor(....RGB2HSV) -cv2" or "rgbtohsv() -skimage"?

Thank you in advance :)

Upvotes: 1

Views: 651

Answers (1)

Yao Houkpati
Yao Houkpati

Reputation: 1

When converting to HSV, CV2 and Skimage use different scales. For CV2, HSV values are within the range of 0 and 255, while for skimage HSV values are within the range of 0 and 1. Just multiply the HSV values from skimage and convert them into integer and you will get the same values for both CV2 and SKIMAGE.

Upvotes: 0

Related Questions