我想运行一个函数,通过python中的数据帧创建图像

2024-10-03 15:33:58 发布

您现在位置:Python中文网/ 问答频道 /正文

This is a screenshot of the dataframe我对python非常陌生,如果您能为我的问题提供任何帮助或建议,我将不胜感激。 因此,我创建了一些非常简单的代码行,将两个相邻的图像合并在一起,但是现在我想对80对图像的列表执行该操作,我已经使用pd.read\U表格来自熊猫。任何建议,即使只是关于在哪里搜索,以了解更多,是非常感谢,因为我只是停留在哪里寻找。你知道吗

 from PIL import Image
import os
os.chdir("/Users/someone/Documents/stimuli_final")

img = Image.open("/Users/me/Documents/StimuliOnly/1_5_1_n1.bmp")
img = img.resize((1280, 1280))
img1 = Image.open("/Users/me/Documents/StimuliOnly/1_10_1_n2.bmp")
img1 = img1.resize((1280, 1280))
bi = Image.new("RGBA", (2760, 1280), ("#808080"))
bi.paste(img, (0,0,1280,1280))
bi.paste(img1, (1480,0,2760,1280))
bi.save("stim5with14vs28congruent.png")

Tags: 图像imageimportimgosopenusers建议
1条回答
网友
1楼 · 发布于 2024-10-03 15:33:58

如果您在excel文件中添加了另一个标题为“输出文件名”的列并填充了该列,则可以使用以下内容:

def helper(data):
    path1, path2, output_file_name = data["Bild 1"], data["Bild 2"], data["output file name"]
    img = Image.open(path1)
    img = img.resize((1280, 1280))
    img1 = Image.open(path2)
    img1 = img1.resize((1280, 1280))
    bi = Image.new("RGBA", (2760, 1280), ("#808080"))
    bi.paste(img, (0,0,1280,1280))
    bi.paste(img1, (1480,0,2760,1280))
    bi.save(output_file_name)

df.apply(helper, axis=1)

相关问题 更多 >