Ask Your Question
2

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

asked Apr 4 '13

neeraj gravatar image

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

Preview: (hide)

1 answer

Sort by » oldest newest most voted
4

answered Apr 5 '13

Guanta gravatar image

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.)
Preview: (hide)

Comments

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...

davidever gravatar imagedavidever (Apr 12 '14)edit

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

Guanta gravatar imageGuanta (Apr 12 '14)edit

Question Tools

Stats

Asked: Apr 4 '13

Seen: 30,049 times

Last updated: Apr 05 '13