# 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[1]-circle[2], circle[1]+circle[2]+1), cv::Range(circle[0]-circle[2], circle[0]+circle[2]+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[0] 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...

( 2014-04-12 05:53:18 -0500 )edit

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

( 2014-04-12 06:24:02 -0500 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2013-04-04 12:15:26 -0500

Seen: 25,549 times

Last updated: Apr 05 '13