Ask Your Question
2

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

asked 2013-04-04 12:15:26 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-04-05 08:19:16 -0600

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.)
edit flag offensive delete link more

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 ( 2014-04-12 05:53:18 -0600 )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 ( 2014-04-12 06:24:02 -0600 )edit

Question Tools

Stats

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

Seen: 29,400 times

Last updated: Apr 05 '13