用Python将一幅图像混合到另一幅图像中

huangapple go评论57阅读模式
英文:

Blend an image into another with Python

问题

我正在尝试使用Python将一幅图像混合到另一幅图像中,以将其设置为壁纸,用于淡入动画的每一帧。我查看了一些论坛,但没有找到任何人尝试做同样的事情,而且我以前从未在Python中进行过照片编辑,只是游戏相关的内容,而我现在正在做的完全不同。

英文:

I am trying to blend an image into another with python to set as your wallpaper for every frame of the fading animation.

I've look on several fourms and haven't found anyone trying to do the same thing and I have never messed with photo editing in python just game stuff and what im doing is completely different.

答案1

得分: 0

I have two png pictures, a smily and a green triangle. Then you can use openCV to perform operations like this:

import cv2
import numpy as np

image1 = cv2.imread('Face1.png')
image2 = cv2.imread('Nose1.png')

print(f"Size of image 1 and image 2 is {image1.shape} and {image2.shape}")
image2_resized = cv2.resize(image2, (image1.shape[1], image1.shape[0]))
print(f"After reshaping, image 1 and image 2 (after resizing) are {image1.shape} and {image2_resized.shape}")

blended_image = cv2.addWeighted(src1=image1, alpha=0.5, src2=image2_resized, beta=0.5, gamma=0)

#cv2.imshow('Im1', image2)
#cv2.imshow('Im2', image2)
cv2.imshow('Blended', blended_image)

cv2.waitKey(0)

Output:

用Python将一幅图像混合到另一幅图像中

英文:

I have two png pictures a smily and a green triangle. Than you can do e.g. with openCV something like:

import cv2
import numpy as np 

image1 = cv2.imread('Face1.png') 
image2 = cv2.imread('Nose1.png')

print(f"Size image 1 and image 2 is {image1.shape} and {image2.shape}")
image2_resized = cv2.resize(image2, (image1.shape[1],image1.shape[0])) 
print(f"After reshape image 1 and image 2 (after resizing) is {image1.shape} and {image2_resized.shape}")

blended_image = cv2.addWeighted(src1=image1,alpha=0.5,src2=image2_resized,beta=0.5,gamma=0)

#cv2.imshow('Im1',image2) 
#cv2.imshow('Im2',image2)
cv2.imshow('Blended',blended_image) 

cv2.waitKey(0)

Output:

用Python将一幅图像混合到另一幅图像中

huangapple
  • 本文由 发表于 2023年2月6日 06:40:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定