32 lines
859 B
Python
32 lines
859 B
Python
#!/usr/bin/env python
|
||
# -*- coding: UTF-8 -*-
|
||
"""
|
||
@Project :trinity_client
|
||
@File :conversion_image.py
|
||
@Author :周成融
|
||
@Date :2023/8/21 10:40:29
|
||
@detail :
|
||
"""
|
||
import numpy as np
|
||
|
||
|
||
# def rgb_to_rgba(rgb_size, rgb_image, mask):
|
||
# alpha_channel = np.full(rgb_size, 255, dtype=np.uint8)
|
||
# # 创建四通道的结果图像
|
||
# rgba_image = np.dstack((rgb_image, alpha_channel))
|
||
# alpha_channel = np.where(mask > 0, 255, 0)
|
||
# # 更新RGBA图像的透明度通道
|
||
# rgba_image[:, :, 3] = alpha_channel
|
||
# return rgba_image
|
||
|
||
def rgb_to_rgba(rgb_image, mask):
|
||
# 创建全透明的alpha通道
|
||
alpha_channel = np.where(mask > 0, 255, 0).astype(np.uint8)
|
||
# 合并RGB图像和alpha通道
|
||
rgba_image = np.dstack((rgb_image, alpha_channel))
|
||
return rgba_image
|
||
|
||
|
||
if __name__ == '__main__':
|
||
image = open("")
|