OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 11 Jan 2017 05:26:58 -0600How to subtract a constant from a 3 channel mat ?http://answers.opencv.org/question/122331/how-to-subtract-a-constant-from-a-3-channel-mat/ I have a Mat CV_8UC3. I want to let the new value be
Mat = 255 - Mat;
but the results are blue. How do let every element be 255 - element ?Wed, 11 Jan 2017 04:24:36 -0600http://answers.opencv.org/question/122331/how-to-subtract-a-constant-from-a-3-channel-mat/Answer by berak for <p>I have a Mat CV_8UC3. I want to let the new value be</p>
<p>Mat = 255 - Mat;</p>
<p>but the results are blue. How do let every element be 255 - element ?</p>
http://answers.opencv.org/question/122331/how-to-subtract-a-constant-from-a-3-channel-mat/?answer=122332#post-id-122332you need a 3-channel value to subtract from, else it does something like 0 - value, which gets saturated to 0, so:
1.
mat = Scalar(255,255,255) - mat;
2.
subtract(Scalar(255,255,255), mat, mat);
Wed, 11 Jan 2017 05:26:58 -0600http://answers.opencv.org/question/122331/how-to-subtract-a-constant-from-a-3-channel-mat/?answer=122332#post-id-122332