Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Multiplication between Mat and Scalar

$
0
0
For a given mask image (binary `cv::Mat M`), I'd like to color (`cv::Scalar C`) the white pixels of `M`. In general, I think this problem is an element-wise multiplication between `cv::Mat` and `cv::Scalar`, like: `M2 = M*C` where I am expecting: [0 1 0 ...] [Scalar(0,0,0) Scalar(b,g,r) Scalar(0,0,0) ...] [0 1 1 ...] * Scalar(b,g,r) = [Scalar(0,0,0) Scalar(b,g,r) Scalar(b,g,r) ...] [0 0 0 ...] [Scalar(0,0,0) Scalar(0,0,0) Scalar(0,0,0) ...] but actually there is no definition of `operator*` between `cv::Mat` and `cv::Scalar`. What is a good alternative? Computing an image for each channel (i.e. `M*b`, `M*g`, `M*r`) and then compose a single image by cv::merge would be a solution, but I feel it might not be computationally efficient. (or is this a best way?)

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>