I have something weird going on, I am attempting to find the median colour in a numpy array. If I work in the BGR/RGB colour space then I find the correct median. If I work in the LUV colour space then I get an incorrect median and the median colour found doesn't even exist in the input list.
Why do I get a different/incorrect median when working in the LUV colour space?
Below shows the median I have found when working in BGR (left), the median when working in LUV (middle) and the input/src image (right):
That brown colour (middle) is the LUV median converted to BGR. There is no brown in the image though?
Below is my code and the original src image:
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)