After segmentation, I have labels
and gray
images. I would like to compute average intensity for each label, i.e. mean of intensity values where label pixels have a particular value. Something like this:
// both are 1-channel
cv::Mat gray, labels
// ...
float avg=cv::mean(gray(labels==1));
cv::MatExpr does not convert (at least not automatically) to cv::Range which could be used as ROI for the gray image, so this example does not compile.
Is there an easy way for this, except of writing the loop explicitly?