【问题标题】:Photos side by side并排的照片
【发布时间】:2021-03-28 05:47:29
【问题描述】:
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,因为它会在笛卡尔平面内打印图像。

更新

我得到了这个,但它不是那么干净:

enter image description here

【问题讨论】:

    标签: python image ipython side-by-side


    【解决方案1】:

    您可以使用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')
    

    【讨论】:

    • 我也会很有趣地在印刷品中显示一些小描述。我该怎么做?
    • 不知道您是否尝试过您的代码,但您的导入不适合
    • 我做到了,但 StackOverflow 无济于事地“更正”了我的拼写!我添加了一个注释的想法。我不是建议你使用我的配色方案,只是让你可以看到哪些参数会影响什么。
    • 显然您可以通过更改第二个paste() 偏移量在图片之间留一个空格。你可以使用透明背景。你可以改变字体大小和样式......但你明白了。
    猜你喜欢
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 2020-03-19
    相关资源
    最近更新 更多