Median value doesn't exist in the input list?

asked 2019-04-22 16:59:37 -0500

sazr gravatar image

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):

enter image description here

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)

enter image description here

edit retag flag offensive close merge delete

Comments

Median opeators means that you can sort values. What is median value in a n-dimensional space?

LBerger gravatar imageLBerger ( 2019-04-23 02:05:29 -0500 )edit