from IPython.display import Image, display
print("Une vraie vieille photo de notre dataset OldRealPhotos")
display(Image('targetdir/OldRealPhotos/photo_1023.jpg', width = 600, height = 600))
print("Vieille photo créée artificiellement de notre dataset SynthOldPhotos")
display(Image('targetdir/SynthOldPhotos/2007_000027.jpg', width = 600, height = 600))
此代码将两张图片一张一张地插入。我想把这两张照片并排放在我的笔记本上。我怎样才能做到这一点?我不想使用
matplotlib
因为它打印笛卡尔计划内的图像。
更新
我得到了这个,但它不是那么干净:
您可以使用
PIL/Pillow
将两个图像并排组合并显示结果:
#!/usr/bin/env python3
from PIL import Image, ImageOps, ImageDraw
# Open input images and annotate
im1 = Image.open('1.jpg') # 600x600 red
im2 = Image.open('2.jpg') # 600x600 blue
# Make double-width canvas for both
both = Image.new('RGB', (1200,600))
# Paste im1 and im2 onto canvas
both.paste(im1)
both.paste(im2, (600,0))
# Add yellow space below and annotate
thickness=50
both = ImageOps.expand(both, border=(0,0,0,thickness), fill=(255,255,0))
draw = ImageDraw.Draw(both)
draw.text((0,600), "Nouvelle photo peu interessante", fill=(0,0,0))
draw.text((600,600), "Nouvelle photo encore moins interessante", fill=(255,0,255))
# Display
both.save('both.png')