40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
# @Time : 2022-7-26 0026 17:44
|
||
# @Author : Qing
|
||
# @Email : derighoid@gmail.com
|
||
# @File : Image_Mix.py
|
||
# @Software: PyCharm
|
||
import PIL
|
||
import matplotlib.pyplot as plt
|
||
import numpy as np
|
||
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)
|
||
img2 = Image.open(imagePath2)
|
||
# 调用图片混合函数
|
||
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()
|