简体   繁体   中英

Using the Matrix operations of OpenCv (Addition and Subtraction) OpenCV C++

I added two images together using the addweighted function of openCV

addWeighted(ROI,1,watermark,0.5,0.0,ROI); 

however , when i try to do the reverse , I get patches of black instead of removing the second image from the resultant image .

addWeighted(ROI,1,watermark,-0.5,0.0,ROI);

I have tried using subtract as well but I am getting the same result. The image below describes what I'm talking about. Do note that my algorithm did not correctly detect all the watermarked areas, but for those which were detected correctly, I am unable to subtract the watermark from it.

在此处输入图片说明

It would be greatly appreciated if you guys could advise me on what to do for the subtraction.

Thank you.

According to docs of addWeighted you are giving half weight to watermark (can you explain why?) and your last argument is depth type...not array...so it should be -1 if watermark and ROI are of the same depth or you put the depth value you want to put...if you note in the docs the final value is a saturated value ...that is if it exceeds 255 it is being pulled down to 255...so no wonder if you subtract you won't get the two exact value.

** EDIT:** for you I + 0.5W = R where I is the lena image, W is the watermark and R is the resultant image. Since R is getting truncated above 255 so store the R in an integer matrix CV_32UC3 . Since you are using OpenCV 2.1 so its better you perform the weighted addition by scanning the image rather than using OpenCV API. That way you can save the R in an integer matrix where the max value you can get is (255 + 255), which will be easily stored. For display use the uchar matrix (truncated one) and for reversing the process use the integer matrix...

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM