I need a bitwise AND on all (3) channels of a matrix and tried this way:
Mat img(5,5,CV_8UC3);
Mat chTmp, chRes;
extractChannel(img, chTmp, 0);
extractChannel(img, chRes, 1);
bitwise_and(chTmp, chRes, chRes);
extractChannel(img, chTmp, 2);
bitwise_and(chTmp, chRes, chRes);
But extractChannel seems to allocate/ copy (?) the contents of the channels, which is costly.
Is there a better way? E.g. only access/ address the 3 channels when building chRes, without a tmp channel?
Perhaps, using
cv::Mat::reshape()andcv::Mat::col()will be able to avoid data copy to extract channels.But I don't know this is efficient or not.