Issue
This is a screenshot of the dataframeI'm really new to python and I would appreciate any help or recommendations for my problem. So I created a few really simple lines of code that merge two images next to each other, but now I want to do that operation for a list of 80 pairs of images, that I have already put into a 80 x 2 dataframe using pd.read_excel from pandas. Any suggestions, even if just about where to search to find out more, are greatly appreciated, since I'm just stuck as to where to look.
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")
Solution
If you added another column to your excel file titled "output file name" and filled that column, you could use something like the following:
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)
Answered By - AndrewH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.