0
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))

This code insert two pictures one under the other. I would like to have these two pictures side by side in my notebook. How can I do that? I don't want to use matplotlib because it prints the images inside a Cartesian plan.

UPDATE

I got this, but it is not that clean:

enter image description here

Robert
  • 7
  • 3

1 Answers1

0

You could use PIL/Pillow to combine the two images side-by-side and display the result:

#!/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')

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I would be interesting in showing the little description in the print as well. How can I do that? – Robert Dec 17 '20 at 15:04
  • Don't know if you tried your code, but your import doesn't fit – Robert Dec 17 '20 at 15:29
  • I did, but StackOverflow unhelpfully *"corrects"* my spelling! I have added an idea for annotation. I am not suggesting you use my colour-scheme, it's just so you can see which parameters affect what. – Mark Setchell Dec 17 '20 at 15:31
  • Obviously you could leave a space between the pictures by changing the 2nd `paste()` offset. And you could use a transparent background. And you could change the font size and style... but you get the idea. – Mark Setchell Dec 18 '20 at 07:58