Skip to content
Advertisement

RGB average of circles

I’m using OpenCV and PIL in Python. I have 96 circles detected with their center coordinates and radios. I need the average RGB from each circles.

Each circle has 6000 pixels, so I thinks iterate one to one it is not efficient.

How can I extract the average RGB from each circle? I am ready to use any other library if it suits my use-case.

Advertisement

Answer

Finally I get it, this is the solution:

circle_img = np.zeros((color_img.shape[0],color_img.shape[1]), np.uint8) #Creamos mascara (matriz de ceros) del tamano de la imagen original
cv2.circle(circle_img,(x_center,y_center),radio,(255,255,255),-1) #Pintamos los circulos en la mascara
datos_rgb = cv2.mean(color_img, mask=circle_img)[::-1]
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement