python - 我想运行一个通过python中的数据框创建图像的函数
问题描述
这是我对 python 非常陌生的数据框的屏幕截图,如果我的问题有任何帮助或建议,我将不胜感激。所以我创建了几行非常简单的代码来合并两个相邻的图像,但现在我想对包含 80 对图像的列表执行该操作,我已经使用 pd.来自熊猫的 read_excel。任何建议,即使只是关于在哪里搜索以了解更多信息,都非常感谢,因为我只是不知道在哪里看。
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")
解决方案
如果您在 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)
推荐阅读
- c# - 在随机行和列中排列对象
- python - 从运行 python 脚本导入变量
- reactjs - 打字稿中的调度类型
- azure-devops - 我有 yaml 管道,它将在 4 个区域中使用 tf 创建我的 az 资源(rg、vnet、aks ..)。使用相同的 piplin 我想在 2 个区域中创建 acr?
- css - 我有一个 CSS,我希望它内联对齐
- node.js - 无法在 nodejs 应用程序中设置 addFollower 方法的 null 属性 -hashed_password
- redis - 如何使用 terraform 调用 gcloud 命令
- java - 进入网页后每分钟开始执行一个动作
- python - Python 中的 Isset() 等价物
- c# - 集中 Laravel 模型和迁移以供多个 Laravel API 项目使用