For two images, where $A$ is the base image (background) and $B$ is the top image (overlay):

For each pixel value ppp in the images:

$$ \text{Overlay(A, B)}=\begin{cases} 2 \times A \times B & \text{if } A < 0.5 \\ 1 - 2 \times (1 - A) \times (1 - B) & \text{if } A \geq 0.5 \end{cases} $$

The function above has an important characteristic when $A=0.5$, which is that the function remains continuous no matter what value is $B$. As a result, the blended image will have a smooth, seamless appearance, without abrupt transitions, providing a visually continuous effect.D

Here's a NumPy implementation to simulate the Photoshop Overlay blend mode:

# Overlay blend mode function
def overlay_blend(base, overlay):
    result = np.zeros_like(base)
    mask = base < 0.5
    result[mask] = 2 * base[mask] * overlay[mask]
    result[~mask] = 1 - 2 * (1 - base[~mask]) * (1 - overlay[~mask])
    return result
# Apply overlay blend
blended_image = overlay_blend(image2, image1)
# Visualize the images
plt.figure(figsize=(15, 5))

# Display image1 (base)
plt.subplot(1, 3, 1)
plt.imshow((image1)
plt.title('Base Image')
plt.axis('off')

# Display image2 (overlay)
plt.subplot(1, 3, 2)
plt.imshow((image2)
plt.title('Overlay Image')
plt.axis('off')

# Display blended image
plt.subplot(1, 3, 3)
plt.imshow(blended_image)
plt.title('Blended Image (Overlay)')
plt.axis('off')

plt.show()

Result:

image.png