Ask Your Question
1

Png transparent, text problems with glow

asked 2020-02-01 10:51:39 -0600

EvilMegaDroid gravatar image

updated 2020-02-01 12:31:07 -0600

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

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

edit retag flag offensive close merge delete

Comments

there is no transparency in opencv; an image processing lib. Opencv is not photoshop If you want to simulate transparency you must use addweighted

LBerger gravatar imageLBerger ( 2020-02-01 11:10:45 -0600 )edit

@LBerger I'm using addWeighted and I can get transparency just that I can't get it the way I wanted.

I will add a result to show what output I get

EvilMegaDroid gravatar imageEvilMegaDroid ( 2020-02-01 11:18:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-02-01 12:07:19 -0600

LBerger gravatar image

updated 2020-02-01 13:02:33 -0600

My english is too bad to explain. Try :

import numpy as np
import cv2

# importing the main image
image = cv2.imread("C:/Users/Laurent/Desktop/flower.jpg")
# importing the logo image
watermark = cv2.imread("C:/Users/Laurent/Desktop/ydzJrDY.png",cv2.IMREAD_UNCHANGED)
(wH, wW) = watermark.shape[:2]
weight = 1 - watermark[:,:,3] / 255 
image[150:150+wH,200:200+wW,0] = np.multiply(image[150:150+wH,200:200+wW,0], weight).astype(np.uint8)
image[150:150+wH,200:200+wW,1] = np.multiply(image[150:150+wH,200:200+wW,1], weight).astype(np.uint8)
image[150:150+wH,200:200+wW,2] = np.multiply(image[150:150+wH,200:200+wW,2], weight).astype(np.uint8)
output = cv2.addWeighted(image[150:150+wH,200:200+wW],1, watermark[:,:,0:3], 1,1)
image[150:150+wH,200:200+wW] = output
#cv2.copyTo(watermark[:,:,0:3],mask.astype(np.uint8),image[150:150+wH,200:200+wW])
cv2.imwrite("C:/Users/Laurent/Desktop/watermark.png",image)
cv2.imshow("output", image)
cv2.waitKey(0)
cv2.destroyAllWindows()

image description

edit flag offensive delete link more

Comments

I can already get this. The problem is getting the shadows from the text. If you see the watermark it has black shadow around the text (glow). I'm trying to get that into the image.

EvilMegaDroid gravatar imageEvilMegaDroid ( 2020-02-01 12:18:27 -0600 )edit

I updated my post to show an example of what I'm looking to get.

EvilMegaDroid gravatar imageEvilMegaDroid ( 2020-02-01 12:29:19 -0600 )edit
1

Thanks it works, I found a solution with PILL too but its great that you made it work with cv2 (since I had to use cv2 for some calculations)

EvilMegaDroid gravatar imageEvilMegaDroid ( 2020-02-01 14:25:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-01 10:51:39 -0600

Seen: 2,202 times

Last updated: Feb 01 '20