Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OpenCV Python, watermark can't be seen on white backgrounds

I am trying to paste my watermark to white-backgrounded image:

        watermark = cv2.imread(watermark_path)
        watermark_ratio = round(image.shape[1]/8)       # calculating the ratio 
        resized_watermark = cv2.resize(watermark, (watermark_ratio, round(watermark_ratio/2)), interpolation = cv2.INTER_AREA)    # resizing watermark size

        h_logo, w_logo, _ = resized_watermark.shape
        h_img, w_img, _ = image.shape
        top_y = h_img - h_logo
        left_x = w_img - w_logo
        bottom_y = h_img
        right_x = w_img

        destination = image[top_y:bottom_y, left_x:right_x]
        result = cv2.addWeighted(destination, 1, resized_watermark, 0.5, 0)     # pasting watermark on original image
        image[top_y:bottom_y, left_x:right_x] = result

        cv2.imwrite(save_path, image)          # saving watermarked the image

But I can’t see watermark on white-backgrounded images, and I think I have to play with parameters of addWeighted method. This happens:

Note: Watermark is pasted to the bottom right corner.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Watermark

Image with watermark (some life signs from watermark)

Image with watermark #2

Image with watermark on darker background

>Solution :

The problem is caused by an incorrect usage of cv2.addWeighted, in thie line:

result = cv2.addWeighted(destination, 1, resized_watermark, 0.5, 0)

The 2nd parameter (you set to 1) is the weight of the first image.

If you want a blend of 50-50 between the image and the watermark, you should change it to:

result = cv2.addWeighted(destination, 0.5, resized_watermark, 0.5, 0)

See the documentation: addWeighted.
And a usage example: Adding (blending) two images using OpenCV.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading