Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Image blending results as a noise

I'm trying to blend 3 images in the following order:
1. base.png
2. photo.png
3. effect.png

I'm trying to overlay photo.png over base.png and on top of resulting image i'm overlaying effect.png

background = cv2.imread('base.png')
overlay = cv2.imread('photo.png', -1)

x_offset = 386
y_offset = 70

base_photo = img_overlay(background, overlay, x_offset, y_offset)

overlay = cv2.imread('effect.png', -1)
final_photo = img_overlay(base_photo, overlay, 0, 0)

cv2.imwrite(result, final_photo) 
def img_overlay(background, overlay, x_offset, y_offset):
    y1, y2 = y_offset, y_offset + overlay.shape[0]
    x1, x2 = x_offset, x_offset + overlay.shape[1]

    alpha_s = overlay[:, :, 3] / 255.0
    alpha_l = 1.0 - alpha_s

    for c in range(0, 3):
        background[y1:y2, x1:x2, c] = (alpha_s * overlay[:, :, c] +
                                   alpha_l * background[y1:y2, x1:x2, c])

    return background

The result i'm getting is Here
The first overlay works ok and gives me base + photo blended image but the second one ruins everything.
Where is my mistake?

Image blending results as a noise

I'm trying to blend 3 images in the following order:
1.

image description

  1. base.png
    2.
  2. photo.png
    3.
  3. effect.png

I'm trying to overlay photo.png over base.png and on top of resulting image i'm overlaying effect.png

background = cv2.imread('base.png')
overlay = cv2.imread('photo.png', -1)

x_offset = 386
y_offset = 70

base_photo = img_overlay(background, overlay, x_offset, y_offset)

overlay = cv2.imread('effect.png', -1)
final_photo = img_overlay(base_photo, overlay, 0, 0)

cv2.imwrite(result, final_photo) 
def img_overlay(background, overlay, x_offset, y_offset):
    y1, y2 = y_offset, y_offset + overlay.shape[0]
    x1, x2 = x_offset, x_offset + overlay.shape[1]

    alpha_s = overlay[:, :, 3] / 255.0
    alpha_l = 1.0 - alpha_s

    for c in range(0, 3):
        background[y1:y2, x1:x2, c] = (alpha_s * overlay[:, :, c] +
                                   alpha_l * background[y1:y2, x1:x2, c])

    return background

The result i'm getting is Here
The first overlay works ok and gives me base + photo blended image but the second one ruins everything.
Where is my mistake?

Image blending results as a noise

I'm trying to blend 3 images in the following order:

image description

  1. base.png
  2. photo.png
  3. effect.png

I'm trying to overlay photo.png over base.png and on top of resulting image i'm overlaying effect.png

background = cv2.imread('base.png')
overlay = cv2.imread('photo.png', -1)

x_offset = 386
y_offset = 70

base_photo = img_overlay(background, overlay, x_offset, y_offset)

overlay = cv2.imread('effect.png', -1)
final_photo = img_overlay(base_photo, overlay, 0, 0)

cv2.imwrite(result, final_photo) 
def img_overlay(background, overlay, x_offset, y_offset):
    y1, y2 = y_offset, y_offset + overlay.shape[0]
    x1, x2 = x_offset, x_offset + overlay.shape[1]

    alpha_s = overlay[:, :, 3] / 255.0
    alpha_l = 1.0 - alpha_s

    for c in range(0, 3):
        background[y1:y2, x1:x2, c] = (alpha_s * overlay[:, :, c] +
                                   alpha_l * background[y1:y2, x1:x2, c])

    return background

The result i'm getting is Here
The first overlay works ok and gives me base + photo blended image but the second one ruins everything.
Where is my mistake?

Image blending results as a noise

I'm trying to blend 3 images in the following order: images.

  1. First i overlay photo.png over base.png with some positioning. And it works.

base_photo.png

  1. photo.png
  2. effect.png

I'm Second i'm trying to overlay photo.png effect.png

effect.png

over base.png and on top of resulting image i'm overlaying effect.pngfrom previous step. The result looks like this

result.png

I'm using opencv blending described here. I've tried to use cv2.addWeighted but the result was the same

background = cv2.imread('base.png')
overlay = cv2.imread('photo.png', -1)

x_offset = 386
y_offset = 70

base_photo = img_overlay(background, overlay, x_offset, y_offset)

overlay = cv2.imread('effect.png', -1)
final_photo = img_overlay(base_photo, overlay, 0, 0)

cv2.imwrite(result, final_photo) 
# blending function
def img_overlay(background, overlay, x_offset, y_offset):
    y1, y2 = y_offset, y_offset + overlay.shape[0]
    x1, x2 = x_offset, x_offset + overlay.shape[1]

    alpha_s = overlay[:, :, 3] / 255.0
    alpha_l = 1.0 - alpha_s

    for c in range(0, 3):
        background[y1:y2, x1:x2, c] = (alpha_s * overlay[:, :, c] +
                                   alpha_l * background[y1:y2, x1:x2, c])

    return background

# First step
background = cv2.imread('base.png')
overlay = cv2.imread('photo.png', -1)
x_offset = 386
y_offset = 70
base_photo = img_overlay(background, overlay, x_offset, y_offset)

# Second step
overlay = cv2.imread('effect.png', -1)
final_photo = img_overlay(base_photo, overlay, 0, 0)

cv2.imwrite(result, final_photo)

The result i'm getting is Here
The first overlay works ok and gives me base + photo blended image but the second one ruins everything.
Where is my mistake?
How i can fix img_overlay function so it will overlay effect.png correctly?

Image blending results as a noise

I'm trying to blend 3 images.

  1. First i overlay photo.png over base.png with some positioning. And it works.

base_photo.png

  1. Second i'm trying to overlay effect.png

effect.png

over resulting image from previous step.

The result looks like this

result.png

I'm using opencv blending described here. I've tried to use cv2.addWeighted but the result was the same

# blending function
def img_overlay(background, overlay, x_offset, y_offset):
    y1, y2 = y_offset, y_offset + overlay.shape[0]
    x1, x2 = x_offset, x_offset + overlay.shape[1]

    alpha_s = overlay[:, :, 3] / 255.0
    alpha_l = 1.0 - alpha_s

    for c in range(0, 3):
        background[y1:y2, x1:x2, c] = (alpha_s * overlay[:, :, c] +
                                   alpha_l * background[y1:y2, x1:x2, c])

    return background

# First step
background = cv2.imread('base.png')
overlay = cv2.imread('photo.png', -1)
x_offset = 386
y_offset = 70
base_photo = img_overlay(background, overlay, x_offset, y_offset)

# Second step
overlay = cv2.imread('effect.png', -1)
final_photo = img_overlay(base_photo, overlay, 0, 0)

cv2.imwrite(result, final_photo)

How i can fix img_overlay function so it will overlay effect.png correctly?