Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

given, that a ROI is rectangular by nature, you will have to work around that using a mask, which will retain only pixels inside a circle:

Mat img = imread("small1.png", 0); // load gray
Rect region(10,10,40,40); // example roi
Mat roi(img, region);  // part of img
Mat mask(Size(40,40), CV_8U, Scalar(0)); // all black
circle(mask, Point(20,20), 20, Scalar(255), -1, LINE_AA); // filled circle
Mat circRoi;
bitwise_and(roi, roi, circRoi, mask); // retain only pixels inside the circle
//
// now you can do your intensity calculation on circRoi
//
imshow("circle masked", mask);
imshow("masked roi", circRoi);
waitKey();

starting from an image:

image description

here's the mask, and the masked roi:

image description image description