python-3.x opencv与skimage之间的HSV颜色空间转换

insrf1ej  于 2023-03-04  发布在  Python
关注(0)|答案(1)|浏览(150)

我比较了skImage HSV色彩空间和OpenCV HSV色彩空间转换方法之间的差异,我发现以下差异,我不明白:

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

我使用PIL来确保我正在输入RGB数组。在这里,当我打印图像时,我得到了以下输出。

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.为什么我的y1和y2数组是不同的?skimage和opencv在相同的颜色空间中遵循不同的转换公式吗?
1.以下哪种是将RGB图像转换为HSV图像的标准和最常用的方法:"cvt颜色(... RGB2HSV)-cv2"还是"rgbtohsv()-皮肤图像"?
提前感谢你们:)

cwtwac6a

cwtwac6a1#

当转换为HSV时,CV2和Skimage使用不同的比例。对于CV2,HSV值在0到255的范围内,而对于skimage,HSV值在0到1的范围内。只需乘以skimage的HSV值并将其转换为整数,您将获得CV2和SKIMAGE相同的值。

相关问题