能否使用一个python脚本
把.png图片的白色(255,255,255)的值
变成png自带的透明色
用image库,可以这么写
from PIL import Image
# 打开图片
img = Image.open("example.png")
# 获取图片的宽度和高度
width, height = img.size
# 将白色(255,255,255)替换为透明色
for x in range(width):
for y in range(height):
pixel = img.getpixel((x, y))
if pixel == (255, 255, 255):
img.putpixel((x, y), (0, 0, 0, 0))
# 保存修改后的图片
img.save("example_transparent.png")
主要思路为,先利用matplotlib读取多张图像,并转换为多个2维数组,再通过拼接多个2维数组到3维,实现单波段到多波段图像的转变,最后利用mode函数挑出多波段图片中的众数,返回一个单波段png图片。
class png_mode:
'''
png_mode类 用于多张单波段png格式图片组合取众数,最后生成一张由多组众数生成的单波段png图片
read_picture 可读取图片
join_picture 可令单波段图片组合成多波段图片
mode_picture 可取得多波段图片众数
show_picture 可显示并保存众数结果
'''
def __init__(self,picture_path,picture_count):
pass
def read_picture(self):
pass
def join_picture(self):
pass
def mode_picture(self):
pass
def show_picture(self):
pass
写了5个函数进行类的定义,通过上述框架进行需求实现。