输入列表中不存在中值?

2024-09-22 20:34:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有点奇怪,我正试图找到一个numpy数组的中间色。如果我在BGR/RGB颜色空间工作,那么我会找到正确的中间值。如果我在LUV颜色空间工作,那么我得到了一个不正确的中位数,并且找到的中位数颜色甚至不存在于输入列表中。你知道吗

为什么在LUV颜色空间工作时会得到不同/不正确的中值?你知道吗

下面是我在BGR中找到的中间值(左),在LUV中找到的中间值(中)和input/src图像(右):

enter image description here

棕色(中间)是LUV转换成BGR的中值。但图像中没有棕色?你知道吗

下面是我的代码和原始src图像:

bgr = cv2.imread('../../images/red_blue_ex.png')
bgr_median = np.median(bgr, axis=(0,1))
swatch = np.full((25,25,3), bgr_median, dtype='uint8')
cv2.imshow('bgr_median', swatch)

luv = cv2.imread('../../images/red_blue_ex.png')
luv = cv2.cvtColor(luv, cv2.COLOR_BGR2LUV)
luv_median = np.median(luv, axis=(0,1))
swatch = np.full((25,25,3), luv_median, dtype='uint8')
swatch = cv2.cvtColor(swatch, cv2.COLOR_LUV2BGR) 
cv2.imshow('luv_median', swatch)

cv2.imshow('src', bgr)
cv2.waitKey(0)

enter image description here


Tags: 图像src颜色np空间cv2medianimshow