I have a marker array defining different parts of an image, and i need to calculate de mean color of each region defined by the markers. I've got some results, but they don't seem right to me... so I coded this test to see what is happening:
img = cv2.imread(ImgPath)
markers = cv2.connectedComponents(foreground)[1]
markers += 1 # Add one to all labels so that background is 1, not 0
markers[unknown==255] = 0 # mark the region of unknown with zero
markers = cv2.watershed(img, markers)
MARKER = 16
copia=img.copy()
copia[markers==MARKER]=(0,0,255)
average=cv2.mean(copia[markers==MARKER])
copia2=img.copy()
copia2[markers==MARKER]=(0,0,average[0])
print(average)
cv2.imshow('watershed result', labeled_img2)
cv2.imshow('original', img)
cv2.imshow('copia', copia)
cv2.imshow('copia2', copia2)
Note that the definition of "foreground" and "labeled_img2" are not important for the question, so i didn't included them for readability.
The output is as follows:
(85.0, 0.0, 0.0, 0.0)
For some reason the screen capture modifies the color of the image, i don't know why at all, but that's not the issue. From the code above I would expect the two bottom images to be exactly equal. Also, I would expect that the output of "print(average)" was something similar to "(0,0,255)".
The main question is: why cv2.mean(copia[markers==MARKER]) gives a non-red color if I defined copia[markers==MARKER] as red?
Some other related questions are: is there any reason for the format of colors being BGR and not RGB? Which format is the mean output in? RGBA?