Ask Your Question
0

calculate intensity for region of interest

asked 2017-06-12 05:45:20 -0600

louis89 gravatar image

updated 2020-10-29 17:30:11 -0600

hi. good time.I have a gray scale image with a bounding box in it.I want to calculate intensity for bounding box.the resolution of my picture is 720*750 and my rectangle is: rectangle(400,210,70,50).do you have any idea to calculate the intensity for this region of my image?Thanks a lot for you're help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-06-12 05:53:42 -0600

berak gravatar image

you can use cv::mean() for this:

Mat image = ....
Mat roi( image, Rect(400,210,70,50) );
Scalar m = mean(roi);
edit flag offensive delete link more

Comments

Thank for you're answer.I'am beginner in opencv.when I cout m,return me 4 number in [] that Three last is zero .what is this number?

louis89 gravatar imagelouis89 ( 2017-06-12 08:30:15 -0600 )edit

since you use a grayscale image (which has only 1 channel), the 1st number holds the mean inntensity of your ROI. so you could use:

uchar intensity = m[0];

for a color image, you would get 3 numbers, if it also has alpha, all 4 numbers in the Scalar are filled.

berak gravatar imageberak ( 2017-06-12 08:40:35 -0600 )edit

Heartiest congratulations.Exactly what I want.if I want to compare the mean intensity of 2 ROI's,When I do this: Mat roi(frame, Rect(405, 210, 70, 50)); Scalar m = mean(roi); Mat roi2(frame, Rect(365, 185, 150, 100)); Scalar M = mean(roi2); if (mean (roi) > mean (roi2)) cout << "louis89" << endl; my code can't bulid because of sign <.but for == or != it work.why?

louis89 gravatar imagelouis89 ( 2017-06-12 09:27:09 -0600 )edit

there is no > operator for cv::Scalar. but again, since you have grayscale image (need only a single number) you could simply write:

if ( mean(roi1)[0] > mean(roi2)[0] )
berak gravatar imageberak ( 2017-06-12 09:34:43 -0600 )edit
1

thanks a lot.my problem solved.

louis89 gravatar imagelouis89 ( 2017-06-12 09:49:19 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-12 05:45:20 -0600

Seen: 6,562 times

Last updated: Jun 12 '17