Skip to content

Instantly share code, notes, and snippets.

@Chrispassold
Created October 22, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chrispassold/e28c27288ab13a9451a3a1166b6f6877 to your computer and use it in GitHub Desktop.
Save Chrispassold/e28c27288ab13a9451a3a1166b6f6877 to your computer and use it in GitHub Desktop.
import os
import requests
import io
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def show_images_side_by_side(left_images_path, right_images_path):
if len(left_images_path) != len(right_images_path):
raise Exception("Size must be identical")
for n in range(len(left_images_path)):
# read images
img_A = mpimg.imread(left_images_path[n])
img_B = mpimg.imread(right_images_path[n])
# display images
fig, ax = plt.subplots(1, 2)
ax[0].imshow(img_A)
ax[1].imshow(img_B)
# example image url: https://m.media-amazon.com/images/S/aplus-media/vc/6a9569ab-cb8e-46d9-8aea-a7022e58c74a.jpg
def download_image_and_save(url, image_file_path, verbose=False):
r = requests.get(url)
if r.status_code != requests.codes.ok:
assert False, 'Status code error: {}.'.format(r.status_code)
with Image.open(io.BytesIO(r.content)) as im:
im.save(image_file_path)
if verbose:
print('Image downloaded from url: {} and saved to: {}.'.format(url, image_file_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment