Fourth commit
This commit is contained in:
32
Image_Mix.py
32
Image_Mix.py
@@ -4,22 +4,36 @@
|
||||
# @Email : derighoid@gmail.com
|
||||
# @File : Image_Mix.py
|
||||
# @Software: PyCharm
|
||||
|
||||
from PIL import Image
|
||||
import PIL
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import cv2
|
||||
from PIL import Image
|
||||
|
||||
'''
|
||||
img1:图片对象1
|
||||
img2:图片对象2
|
||||
alpha:透明度 ,取值范围为 0 到 1,当取值为 0 时,输出图像相当于 image1 的拷贝,而取值为 1 时,
|
||||
则是 image2 的拷贝,只有当取值为 0.5 时,才为两个图像的中合。因此改值的大小决定了两个图像的混合程度'''
|
||||
|
||||
|
||||
# 阿尔法图像混合
|
||||
def imageMix(imagePath1, imagePath2):
|
||||
'''
|
||||
|
||||
:param imagePath1: 混合图片1的地址
|
||||
:param imagePath2: 混合图像2的地址
|
||||
:return: 混合后的图像
|
||||
'''
|
||||
|
||||
# 获取两张图片
|
||||
img1 = Image.open(imagePath1)
|
||||
im1 = np.array(img1)
|
||||
img2 = Image.open(imagePath2)
|
||||
im2 = np.array(img2)
|
||||
|
||||
img3 = cv2.addWeighted(im1, 0.8, im2, 0.3, 0)
|
||||
# 调用图片混合函数
|
||||
img3 = PIL.Image.blend(img1, img2, 0.5) # 0.5 为gamma 值
|
||||
|
||||
# 展示混合后的图片
|
||||
plt.imshow(img3)
|
||||
|
||||
# 保存图片
|
||||
Image.fromarray(np.uint8(img3)).save("./data/picture14.png")
|
||||
plt.show()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user