python中的新功能我想对一个文件夹中的不同图像应用一种算法,然后将新图像保存到另一个文件夹中生物学研究图像

问题描述

我要反转黑白图像的颜色,然后使用以下代码将背景更改为透明:

imgg = Image.open('HSPl4_E5_LP8.png')
data = np.array(imgg)

converted = np.where(data == 255,255)

imgg = Image.fromarray(converted.astype('uint8'))

imgg.save('new HSPl4_E5_LP8.png')

from PIL import Image
   

img = Image.open('new HSPl4_E5_LP8.png')
img = img.convert("RGBA")
datas = img.getdata()
     
       
newData = []
for item in datas:
    if item[0] == 255 and item[1] == 255 and item[2] == 255:
        newData.append((255,255,0))#0 és la alfa de rgba i significa 0 opacity.
   
    else:
            newData.append(item)
            
    
img.putdata(newData)
img.save("HSPl4_E5_LP8 transparent.png","PNG")

然后,我想在一个文件夹中的多个图像中进行迭代。然后,我想将带有更改的新图像保存到另一个文件夹中。但是我找不到使它起作用的方法。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)