pythonpictureanalysis/Image_Mix.py

40 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-07-26 21:27:11 +08:00
# -*- coding: utf-8 -*-
# @Time : 2022-7-26 0026 17:44
# @Author : Qing
# @Email : derighoid@gmail.com
# @File : Image_Mix.py
# @Software: PyCharm
2022-07-27 20:41:38 +08:00
import PIL
2022-07-26 21:27:11 +08:00
import matplotlib.pyplot as plt
import numpy as np
2022-07-27 20:41:38 +08:00
from PIL import Image
'''
img1图片对象1
img2图片对象2
alpha透明度 取值范围为 0 1当取值为 0 输出图像相当于 image1 的拷贝而取值为 1
则是 image2 的拷贝只有当取值为 0.5 才为两个图像的中合因此改值的大小决定了两个图像的混合程度'''
2022-07-28 21:35:42 +08:00
# 图像混合
2022-07-26 21:27:11 +08:00
def imageMix(imagePath1, imagePath2):
2022-07-27 20:41:38 +08:00
'''
:param imagePath1: 混合图片1的地址
:param imagePath2: 混合图像2的地址
:return: 混合后的图像
'''
# 获取两张图片
2022-07-26 21:27:11 +08:00
img1 = Image.open(imagePath1)
img2 = Image.open(imagePath2)
2022-07-27 20:41:38 +08:00
# 调用图片混合函数
img3 = PIL.Image.blend(img1, img2, 0.5) # 0.5 为gamma 值
2022-07-26 21:27:11 +08:00
2022-07-27 20:41:38 +08:00
# 展示混合后的图片
2022-07-26 21:27:11 +08:00
plt.imshow(img3)
2022-07-27 20:41:38 +08:00
# 保存图片
2022-07-26 21:27:11 +08:00
Image.fromarray(np.uint8(img3)).save("./data/picture14.png")
plt.show()