Ask Your Question
0

Pixel datas in a circular region

asked 2016-08-26 15:06:59 -0600

DT0311 gravatar image

Hi, Just want to ask if it is possible to access the intensity value of all pixels in a circular region at the center of an image? I am very new to openCV and for now I can only set the ROI into a square region.

Thousands of thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-08-27 01:03:17 -0600

berak gravatar image

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

edit flag offensive delete link more

Comments

I have tested this and it works perfectly. Thanks a lot!

DT0311 gravatar imageDT0311 ( 2016-08-30 14:24:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-08-26 15:06:59 -0600

Seen: 3,185 times

Last updated: Aug 27 '16