1
0

ImageUtils.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from datetime import datetime
  2. from PIL import Image
  3. import matplotlib.pyplot as plt
  4. def get_image_date(img_path: str) -> datetime:
  5. """Returns the date from the image EXIF data.
  6. Args:
  7. img_path (str): path to image
  8. Returns:
  9. datetime: datetime extracted from EXIF data
  10. """
  11. img = Image.open(img_path)
  12. date_raw = img.getexif()[306]
  13. return datetime.strptime(date_raw, "%Y:%m:%d %H:%M:%S")
  14. def display_images(images: list, titles: list, colorbar=False, size=8, **imshowargs):
  15. """Displays the given images next to each other.
  16. Args:
  17. images (list of np.ndarray): list of image arrays
  18. titles (list of str): list of titles
  19. colorbar (bool, optional): Display colorbars. Defaults to False.
  20. size (int, optional): plt size per image. Defaults to 8.
  21. """
  22. numImgs = len(images)
  23. plt.figure(figsize=(numImgs * size, size))
  24. for i, image, title in zip(range(numImgs), images, titles):
  25. plt.subplot(1, numImgs, i + 1)
  26. plt.imshow(image, **imshowargs)
  27. plt.title(title)
  28. if colorbar:
  29. plt.colorbar()
  30. plt.tight_layout()
  31. plt.show()