Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Png transparent, text problems with glow

I'm trying to place a logo into a background. The logo has text with glow.

When I put it on the background it only outputs the white part (and removes the black glow)

Here's the code:

import cv2
import numpy as np

# importing the main image
image = cv2.imread("flower.jpg")
# importing the logo image
watermark = cv2.imread("asdasd.png", -1)
(wH, wW) = watermark.shape[:2]


(B, G, R, A) = cv2.split(watermark)
B = cv2.bitwise_and(B, B, mask=A)
G = cv2.bitwise_and(G, G, mask=A)
R = cv2.bitwise_and(R, R, mask=A)
watermark = cv2.merge([B, G, R, A])


(h, w) = image.shape[:2]
image = np.dstack([image, np.ones((h, w), dtype="uint8") * 255])

# construct an overlay that is the same size as the input
# image, (using an extra dimension for the alpha transparency),
# then add the watermark to the overlay in the bottom-right
# corner
overlay = np.zeros((h, w, 4), dtype="uint8")
overlay[h - wH - 10 : h - 10, w - wW - 10 : w - 10] = watermark

# blend the two images together using transparent overlays
output = image.copy()
cv2.addWeighted(overlay, 1, output, 1, 0, output)
cv2.imshow("output", output)
cv2.waitKey(0)
cv2.waitKey(0)

Watermark
watermark

Image
watermark

Png transparent, text problems with glow

I'm trying to place a logo into a background. The logo has text with glow.

When I put it on the background it only outputs the white part (and removes the black glow)

Here's the code:

import cv2
import numpy as np

# importing the main image
image = cv2.imread("flower.jpg")
# importing the logo image
watermark = cv2.imread("asdasd.png", -1)
(wH, wW) = watermark.shape[:2]


(B, G, R, A) = cv2.split(watermark)
B = cv2.bitwise_and(B, B, mask=A)
G = cv2.bitwise_and(G, G, mask=A)
R = cv2.bitwise_and(R, R, mask=A)
watermark = cv2.merge([B, G, R, A])


(h, w) = image.shape[:2]
image = np.dstack([image, np.ones((h, w), dtype="uint8") * 255])

# construct an overlay that is the same size as the input
# image, (using an extra dimension for the alpha transparency),
# then add the watermark to the overlay in the bottom-right
# corner
overlay = np.zeros((h, w, 4), dtype="uint8")
overlay[h - wH - 10 : h - 10, w - wW - 10 : w - 10] = watermark

# blend the two images together using transparent overlays
output = image.copy()
cv2.addWeighted(overlay, 1, output, 1, 0, output)
cv2.imshow("output", output)
cv2.waitKey(0)
cv2.waitKey(0)

Watermark
watermark

Image
watermark

Bad Output
Shadow is missing
bad_output

Png transparent, text problems with glow

I'm trying to place a logo into a background. The logo has text with glow.

When I put it on the background it only outputs the white part (and removes the black glow)

Here's the code:

import cv2
import numpy as np

# importing the main image
image = cv2.imread("flower.jpg")
# importing the logo image
watermark = cv2.imread("asdasd.png", -1)
(wH, wW) = watermark.shape[:2]


(B, G, R, A) = cv2.split(watermark)
B = cv2.bitwise_and(B, B, mask=A)
G = cv2.bitwise_and(G, G, mask=A)
R = cv2.bitwise_and(R, R, mask=A)
watermark = cv2.merge([B, G, R, A])


(h, w) = image.shape[:2]
image = np.dstack([image, np.ones((h, w), dtype="uint8") * 255])

# construct an overlay that is the same size as the input
# image, (using an extra dimension for the alpha transparency),
# then add the watermark to the overlay in the bottom-right
# corner
overlay = np.zeros((h, w, 4), dtype="uint8")
overlay[h - wH - 10 : h - 10, w - wW - 10 : w - 10] = watermark

# blend the two images together using transparent overlays
output = image.copy()
cv2.addWeighted(overlay, 1, output, 1, 0, output)
cv2.imshow("output", output)
cv2.waitKey(0)
cv2.waitKey(0)

Watermark
watermark

Image
watermark

Bad Output
Shadow is missing
bad_output

Good Output
I'm looking to get something like this (this was done with ps, should be possible with programming though) good_output

Png transparent, text problems with glow

I'm trying to place a logo into a background. The logo has text with glow.

When I put it on the background it only outputs the white part (and removes the black glow)

Here's the code:

import cv2
import numpy as np

# importing the main image
image = cv2.imread("flower.jpg")
# importing the logo image
watermark = cv2.imread("asdasd.png", -1)
(wH, wW) = watermark.shape[:2]


(B, G, R, A) = cv2.split(watermark)
B = cv2.bitwise_and(B, B, mask=A)
G = cv2.bitwise_and(G, G, mask=A)
R = cv2.bitwise_and(R, R, mask=A)
watermark = cv2.merge([B, G, R, A])


(h, w) = image.shape[:2]
image = np.dstack([image, np.ones((h, w), dtype="uint8") * 255])

# construct an overlay that is the same size as the input
# image, (using an extra dimension for the alpha transparency),
# then add the watermark to the overlay in the bottom-right
# corner
overlay = np.zeros((h, w, 4), dtype="uint8")
overlay[h - wH - 10 : h - 10, w - wW - 10 : w - 10] = watermark

# blend the two images together using transparent overlays
output = image.copy()
cv2.addWeighted(overlay, 1, output, 1, 0, output)
cv2.imshow("output", output)
cv2.waitKey(0)
cv2.waitKey(0)

Watermark
watermark

Image
watermark

Bad Output
Shadow is missing
bad_output

Good Output
I'm looking to get something like this (this was done with ps, should be possible with programming though) good_outputimage description