# Get the average color of image inside the circle:Hough Transform

Hi, I am a newbie in opencv. I am trying to detect some cells(circular objects) in an image. I have used cv2.HoughCircles to detect multiple circles. Now I need to extract some features of the extracted circles. For that I need to find the average color of my image inside each circle. I am thinking of using the detected circles as a mask and then trying to pull out the average of all the pixels from my corresponding image. Unfortunately, I am unable to accomplish. Is it is correct way of finding the average color of my image inside each circle? Could some one help me out in this?

Thanks

edit retag close merge delete

Sort by » oldest newest most voted

Yes, your approach is the right way to go:

1. get your circles, e.g. via cv::HoughCircles : cv::HougCircles(image, circles); , see the example http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?highlight=houghcircle#cv2.HoughCircles .

2. for circle in circles:

• get the region of interest in your image:

cv::Mat roi = img(cv::Range(circle-circle, circle+circle+1), cv::Range(circle-circle, circle+circle+1))

• create your mask w. the roi-size: cv::Mat1b mask(roi.rows, roi.cols);
• compute the mean: cv::Scalar mean = cv::mean(roi, mask); --> now the Scalar contains the mean values for each channel (i.e. mean is the mean of your blue channel, etc.)
more

Thanks for the answer! Helped me alot, though still struggeling with "create your mask w. the roi-size: cv::Mat1b mask(roi.rows, roi.cols);". Is there really a "mask" function? cant seem to find it...

No, there isn't a mask-function, it's just a matrix with the dimension of the ROI which I named 'mask'.

Official site

GitHub

Wiki

Documentation